Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.8 kB
1
Indexable
Never
import random

def generate_addition_problem():
    a = random.randint(1, 100)
    b = random.randint(1, 100)
    problem = f"\\item (400) $\\Huge{{{a} + {b}}}$"
    return problem

def generate_subtraction_problem():
    a = random.randint(1, 100)
    b = random.randint(1, 100)
    if b > a:
        a, b = b, a
    problem = f"\\item (400) $\\Huge{{{a} - {b}}}$"
    return problem

def generate_multiplication_problem():
    a = random.randint(1, 12)
    b = random.randint(1, 12)
    problem = f"\\item (400) $\\Huge{{{a} \\times {b}}}$"
    return problem

def generate_division_problem():
    a = random.randint(1, 12)
    b = random.randint(1, 12)
    product = a * b
    problem = f"\\item (400) $\\Huge{{{product} \\div {a}}}$"
    return problem

def generate_arithmetic_problems(n):
    problems = []
    for _ in range(n):
        problem_type = random.choice(['addition', 'subtraction', 'multiplication', 'division'])
        
        if problem_type == 'addition':
            problem = generate_addition_problem()
        elif problem_type == 'subtraction':
            problem = generate_subtraction_problem()
        elif problem_type == 'multiplication':
            problem = generate_multiplication_problem()
        elif problem_type == 'division':
            problem = generate_division_problem()
        
        problems.append(problem)
    
    return problems

def save_problems_to_file(problems, filename):
    with open(filename, 'w') as file:
        file.write("\\begin{enumerate}\n")
        for problem in problems:
            file.write(f"{problem}\n")
        file.write("\\end{enumerate}\n")

# Generate 20 problems
problems = generate_arithmetic_problems(20)

# Save to a .tex file
save_problems_to_file(problems, "arithmetic_problems.tex")

print("LaTeX file generated: arithmetic_problems.tex")
Leave a Comment