File size: 833 Bytes
d924141
 
 
984a89c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d924141
984a89c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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