编写math_game.py脚本,实现以下目标:
- 随机生成两个100以内的数字
- 随机选择加法或是减法
- 总是使用大的数字减去小的数字
- 如果用户答错三次,程序给出正确答案
from random import randint, choice
def exam(): counter = 0 while counter < 3: nums = [randint(1, 100) for i in range(2)] nums.sort(reverse=True) op = choice('+-') if op == '-': result = nums[0] - nums[1] else: result = nums[0] + nums[1] prompt = '%s %s %s =' % (nums[0], op, nums[1]) answer = int(input(prompt)) if answer == result: print('very Good') else: print('