如果有人不输入' y'或者' n'?有人可以把它放进我的代码吗?
redo = False
outstanding = 0
satisfactory = 0
unsatisfactory = 0
mark_Total = 0
value = False
while not redo:
try:
mark = input("Enter a mark from 0-100")
if mark < 0 or mark >= 100:
raise ValueError("Invalid Input")
elif mark >= 90:
outstanding += 1
mark_Total += 1
again = raw_input("Do you want to enter another mark? (y/n)")
if again.lower() == "n":
redo = True
答案 0 :(得分:2)
在另一个循环中使用while
循环没什么特别的。
elif mark >= 90:
outstanding += 1
mark_Total += 1
again = 'x'
while again != 'y' and again != 'n':
again = raw_input("Do you want to enter another mark? (y/n)").lower()
if again == "y":
redo = True