0

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.

saZ
  • 89
  • 7
  • 5
    Put a loop around all the inputs. When any of the inputs fails validation, use `continue` to go back to the beginning of the loop. – Barmar Dec 29 '21 at 20:47
  • What have you tried based on your own research, and what went wrong with your attempts? – G. Anderson Dec 29 '21 at 20:54

1 Answers1

0
while True:
    num = int(input("Enter number greater than 10: "))
    if num > 10:
        print("Correct.")
        break
    else:
        print("Imcorrect. Try again.")
Robin Sage
  • 969
  • 1
  • 8
  • 24