假设请求输入一次就满足了使用布尔逻辑的某些条件。稍后,程序请求另一个输入,但不符合标准。在这种情况下,程序应该从一开始就要求用户提供第一个输入,即使它是正确的,因为数字2输入的标准是不正确的。
Example:
Give a number that is bigger than 10: 11
Give a number that is smaller than 11: 23
*wrong number, start again*
Give a number that is bigger than 10: 11
Give a number that is smaller than 11: 9
*great*
这只是一个例子,我对思考过程很感兴趣。到目前为止,如果每个问题的输入不正确,我只会再次问一次。我需要找到一种方法,再次从第一个问题,以防止第二个问题是错误的例子。
不需要任何功能,只有循环。我正在学习编程的思维过程。
发布于 2021-12-29 20:58:17
while True:
num = int(input("Enter number greater than 10: "))
if num > 10:
print("Correct.")
break
else:
print("Imcorrect. Try again.")
https://stackoverflow.com/questions/70524835
复制相似问题