【发布时间】:2022-11-13 07:21:19
【问题描述】:
基本上我有一个程序,你必须让老师耐心等待,然后数“一”、“二”、“三”、“四”、“一”等,当你失败时,它会写下“连胜是...... ,但你失败了”,耐心达到 0 后,老师说“今天够了”,然后忽略所有输入,但是当我收到这样的命令时:
2
one
two
three
four
one
twu
one
two
three
three
在某些情况下,我在启动它时会遇到 EOF 错误,即使我将所有需要的输入转换为整数。 代码:
patience = int(input())
a = input()
streak = 0
mistake = False
one = "one"
two = "two"
three = "three"
four = "four"
nextNum = one
while 1:
if a == nextNum:
mistake = False
streak += 1
if nextNum == one:
nextNum = two
elif nextNum == two:
nextNum = three
elif nextNum == three:
nextNum = four
elif nextNum == four:
nextNum = one
elif not mistake:
mistake = True
nextNum = one
patience -= 1
if patience == 0:
print("The counting streak was " + str(streak) + ", but you failed.")
print("Enough for today.")
if patience >= 1:
print("The counting streak was " + str(streak) + ", but you failed.")
streak = 0
a = input()
我不知道这里有什么问题,因为它就像一个随机的机会,我不明白为什么。
【问题讨论】:
-
使用
https://pythontutor.com/visualize.html#mode=edit尝试您的代码,您会看到逐步执行时会发生什么。 -
每位老师一开始有多少耐心?