math / modules /numbering_system /presentation_bases.py
Sina Media Lab
Updates
74a6085
raw
history blame
1.3 kB
# modules/presentation_bases.py
title = "Bases"
description = "This module covers the presentation of numbers in various bases, including binary, octal, decimal, and hexadecimal."
def generate_question():
import random
# Generate a random base
base = random.choice([2, 8, 10, 16])
# Generate a valid number in that base
number = ''.join(random.choice('0123456789ABCDEF') for _ in range(4))
# Generate incorrect answers
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
}