Python: How do I repeat a false while loop?
我无法让它实际重复while循环。
我试过让它注册一个真值,或者让它继续或突破循环。 但没有任何作用。
1 2 3 4 5 6 7 | xvalue = int(input("Enter a test value to test if it works:")) while xvalue >= Limit: print("\a\a\a") else: continue xvalue = int(input("Updating Value:")) |
有人可以建议吗?
我也写了它,所以它说:
1 2 | else: return True |
但这不起作用。 (我得到一个错误)我只需要它继续重复while循环,直到它在第一个条件成为真。 然后响了。
我并不完全遵循您的代码的意图。我想你想要的东西如下:
1 2 3 4 5 | while True: xvalue = int(input("Enter a value:")) if xvalue < Limit: break print("\a\a\a") |
您的代码存在许多问题,但这里存在一些大问题。
首先,
其次,因为
所以基本上,你要找的是:
1 2 3 4 5 | xvalue = int(input("Enter a test value to see if it works:")) while xvalue >= Limit: print ("\a\a\a") xvalue = int(input("Please try another value:")) |
OP评论后更新:
1 2 3 4 5 6 7 | xvalue = int(input("Enter a test value to see if it works:")) while xvalue < Limit: # Repeats until user gives a value above limit xvalue = int(input("Please try another value:")) else: while True: # Causes bell to ring infinitely print ("\a\a\a") |
Can someone suggest something I've written it so that it says:
else: return True but that doesn't work. I just need it to keep repeating the while loop until it becomes true on the first condition. And then rings.
您可以执行以下操作:
1 2 3 4 5 6 | Value = False while Value == False: #code to do while looping #code to do after looping |
要么:
1 2 3 4 5 6 | Value = False While 1: #code for inside the loop if Value == True break |
此外,你的问题并没有真正描述,所以如果我不理解,不要怪我