我尝试了一切,但似乎找不到问题所在。当我正常运行程序时,它会为我提供所有内容的正确输出。我无法理解 check50 的错误 以下是所需的规范:https://cs50.harvard.edu/python/2022/psets/4/professor/
import random
def main():
level = get_level()
score = 0
for i in range(10):
problem = generate_integer(level)
list = problem.split("=")
prob = list[0]
ans = list[1]
ans = int(ans)
answer = input(prob + "= ")
if answer.isdigit():
answer = int(answer)
else:
print("EEE")
continue
if answer != ans:
print("EEE")
answer1 = input(prob + "= ")
answer1 = int(answer1)
if answer1 == ans:
score += 1
continue
if answer1 != ans:
print("EEE")
answer2 = int(input(prob + "= "))
if answer2 == ans:
score += 1
else:
print(prob + "= " + list[1])
continue
else:
score += 1
print("Score:", score)
def get_level():
while True:
level = input("Level: ")
if level.isdigit():
level = int(level)
else:
continue
if level != 1 and level != 2 and level != 3:
continue
else:
break
return level
def generate_integer(level):
problem = ""
if level == 1:
X = random.randint(1, 9)
Y = random.randint(1, 9)
elif level == 2:
X = random.randint(10, 99)
Y = random.randint(10, 99)
elif level == 3:
X = random.randint(100, 999)
Y = random.randint(100, 999)
problem = f"{X} + {Y} = {X+Y}"
return problem
if __name__ == "__main__":
main()
这段代码
X = random.randint(1, 9)
Y = random.randint(1, 9)
不会“使用 0-9 产生加法问题”