math / modules /presentation_bases.py
Sina Media Lab
Updates
984a89c
raw
history blame
833 Bytes
import random
def generate_question():
number = random.randint(1, 15)
binary_rep = bin(number)[2:].zfill(4)
question_data = {
"question": f"What is the binary representation of the decimal number {number}?",
"options": [bin(i)[2:].zfill(4) for i in random.sample(range(1, 16), 4)],
"correct_answer": binary_rep,
"explanation": f"The decimal number {number} is represented as {binary_rep} in binary.",
"step_by_step_solution": [
f"1. Start with the decimal number {number}.",
"2. Divide the number by 2 and note the quotient and remainder.",
"3. Continue dividing the quotient by 2 until you reach 0.",
"4. The binary representation is formed by reading the remainders from bottom to top."
]
}
return question_data