|
|
|
|
|
title = "Bases" |
|
description = "This module covers the presentation of numbers in various bases, including binary, octal, decimal, and hexadecimal." |
|
|
|
def generate_question(): |
|
import random |
|
|
|
base = random.choice([2, 8, 10, 16]) |
|
|
|
number = ''.join(random.choice('0123456789ABCDEF') for _ in range(4)) |
|
|
|
correct_answer = number |
|
options = [correct_answer] |
|
while len(options) < 4: |
|
invalid_number = ''.join(random.choice('0123456789ABCDEF') for _ in range(4)) |
|
if invalid_number != correct_answer: |
|
options.append(invalid_number) |
|
random.shuffle(options) |
|
|
|
question = f"What is the representation of {number} in base {base}?" |
|
explanation = f"The number {number} in base {base} is {correct_answer}." |
|
step_by_step_solution = [ |
|
"Step 1: Identify the digits.", |
|
"Step 2: Convert each digit based on the base.", |
|
"Step 3: Combine the digits to form the final answer." |
|
] |
|
|
|
return { |
|
"question": question, |
|
"options": options, |
|
"correct_answer": correct_answer, |
|
"explanation": explanation, |
|
"step_by_step_solution": step_by_step_solution |
|
} |
|
|