我的代码中的错误在哪里?我无法找到它们。我不得不制作一个乘法学习程序,但我现在陷入困境。
import random
n = int(input("How many exercises?"))
wrong = 0
abort = False
for k in range(n):
a = random.randint(2, 13)
b = random.randint(2, 13)
help = str(k+1) + ". " + str(a) + " * " + str(b)
answer = input(help + "=> ")
if answer == "":
abort = True
break
if answer !=a * b:
print("Wrong!")
wrong += 1
if abort == True:
print("Noob")
return
if wrong == 0:
print("Good")
else:
print("Hale" ,wrong)
答案 0 :(得分:0)
有两个错误,返回不在函数中,vigu变量在该点没有值,你永远不会到达
如果abort == True: 打印("菜鸟&#34) 返回
因为在此之前你设置abort = True然后你休息一下,
答案 1 :(得分:0)
稍微纠正了您的代码:
以下是我所做的修正:
import random
n = int(input("How many exercises?"))
wrong = 0
abort = False
for k in range(n):
a = random.randint(2, 13)
b = random.randint(2, 13)
help = str(k+1) + ". " + str(a) + " * " + str(b)
answer = input(help + "=> ")
if answer == "":
abort = True
break
if answer != str(a * b):
print("Wrong!")
wrong += 1
if abort == True:
print("Noob")
if wrong == 0:
print("Good")
'''Don't know what you wanted to do here
else:
print("Hale" ,vigu)'''