gpt4 book ai didi

python - 在while循环中如何使用while循环

转载 作者:行者123 更新时间:2023-12-03 09:11:36 25 4
gpt4 key购买 nike

如果有人不输入“y”或“n”,我如何使它在while循环中有一个while循环?有人可以将其放入我的代码中吗?

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

最佳答案

在另一个循环中使用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

关于python - 在while循环中如何使用while循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33286542/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com