简体   繁体   中英

ask again for first input if second input is wrong

Let's say that asking for input once meets certain criteria using boolean logic. Later, the program asks for another input but the criteria are not met. In this case, the program should ask the user for the first input from the beginning even though it was correct because the criteria of the number 2 input was not correct.

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*

This is just an example, I am interested in the thinking process. So far I have done it to only ask again for each question if the input is not correct in each question. I need to find a way to ask again from the first question in case that the second question is wrong as the example.

No functions please, only loops. I am learning the thinking process of programming.

while True:
    num = int(input("Enter number greater than 10: "))
    if num > 10:
        print("Correct.")
        break
    else:
        print("Imcorrect. Try again.")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM