()
| 15 | return validated_guess |
| 16 | |
| 17 | def random_problem(): |
| 18 | operators = { |
| 19 | '+': operator.add, |
| 20 | '-': operator.sub, |
| 21 | '*': operator.mul, |
| 22 | '/': operator.truediv, |
| 23 | } |
| 24 | |
| 25 | num_1 = random.randint(1, 10) |
| 26 | num_2 = random.randint(1, 10) |
| 27 | operation = random.choice(list(operators.keys())) |
| 28 | answer = float(round(operators.get(operation)(num_1, num_2),3)) |
| 29 | print(f'What is {num_1} {operation} {num_2}') |
| 30 | return answer |
| 31 | |
| 32 | def ask_question(): |
| 33 | answer = random_problem() |