File size: 1,300 Bytes
c9ca893
d924141
c9ca893
 
984a89c
c9ca893
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
984a89c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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
    }