import random title = "Presentation in Bases" description = "This module covers the representation of numbers in different bases including binary, octal, decimal, and hexadecimal." def generate_question(): num = random.randint(1, 20) base = random.choice([2, 8, 10, 16]) if base == 2: representation = bin(num)[2:] elif base == 8: representation = oct(num)[2:] elif base == 16: representation = hex(num)[2:] else: representation = str(num) question = f"What is the representation of decimal number {num} in base {base}?" correct_answer = representation options = [correct_answer] # Generate incorrect options while len(options) < 5: fake_option = bin(random.randint(1, 20))[2:] if fake_option not in options: options.append(fake_option) random.shuffle(options) explanation = ( f"The number {num} in base {base} is represented as {representation}." "\n\n**Step-by-step solution:**\n" "1. Convert the number from decimal to the required base.\n" "2. Match with the provided options.\n" "3. The correct answer is the one that matches the conversion." ) return question, options, correct_answer, explanation