(资料图片)
import randomdef plus(): n1 = random.randint(1, 100) n2 = random.randint(1, 100) ans = n1 + n2 for i in range(3): print(n1, "+", n2, "=?") temp = int(input("请输入答案:")) if temp == ans: print("答对了,正确答案是:", ans) break else: print("答错了,再试一次")def minus(): n1 = random.randint(1, 100) n2 = random.randint(1, 100) ans = n1 + n2 for i in range(3): print(ans, "-", n1, "=?") temp = int(input("请输入答案:")) if temp == n2: print("答对了,正确答案是:", n2) break else: print("答错了,再试一次")def times(): n1 = random.randint(1,100) n2 = random.randint(1,10) ans = n1 * n2 for i in range(3): print(n1, "×", n2, "=?") temp = int(input("请输入答案:")) if temp == ans: print("答对了,正确答案是:", ans) break else: print("答错了,再试一次")def divided(): n1 = random.randint(1, 100) n2 = random.randint(1, 10) ans = n1 * n2 for i in range(3): print(ans, "÷", n2, "=?") temp = int(input("请输入答案:")) if temp == n1: print("答对了,正确答案是:", n1) break else: print("答错了,再试一次")while True: temp = 0 a = input("请选择:加法,减法,乘法,除法或退出:") if a == "加法": plus() elif a == "减法": minus() elif a == "乘法": times() elif a == "除法": divided() elif a == "退出": b = input("是否退出?(y或n)") if b == "y": exit() elif b == "n": print("好的") else: print("请重新输入!")
标签:
Copyright © 2015-2023 港澳物业网版权所有 备案号:京ICP备2023022245号-31 联系邮箱:435 226 40 @qq.com