import random def int_generator(): # Generates a random number between 2 and 12 term_1 = random.randint(2,12) term_2 = random.randint(2,12) return term_1, term_2 def ops_generator(): # The list of operators there is to choose from operators = ["+", "-", "*", "/"] # Randomizes the operator for the mathematical question op = random.choice(operators) return op # Calls the functions term_1, term_2 = int_generator() op = ops_generator() # generates the question using the specific operator that is chosen from the # ops_gen function def question_generator(): if op == "+": question = f"{term_1} + {term_2}" elif op == "-": question = f"{term_1} - {term_2}" elif op == "*": question = f"{term_1} x {term_2}" else: question = f"{term_1} / {term_2}" return question question = question_generator() answer = round(eval(question), 1) print(f"The chosen question is: {question}") print(f"The answer is: {answer}")