1

I'm trying to check user's input (3 numbers currently) for having numbers only. And if it's not numbers but anything else, to make the user enter again until all three input would be numbers.

It's ok in terms of finding wrong input, but instead of making user input again, the program just stops.

It does work without a list, so i think it has something to do with the sequence of loops

its=[]
entering=True
while entering:
  for x in range(3):
    try:
      x=int(input("enter the number:"))
      print("your input is:"+str(x))
      its.append(x)
      entering=False
    except (SyntaxError, ValueError):
      print("not gonna work")
      continue
  • 1
    Possible duplicate of [Asking the user for input until they give a valid response](https://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – rdas Jun 01 '19 at 17:30

1 Answers1

0

In the while loop, you can check the number of items in the list until it reaches the amount you want (In this case, 3).

its = []
while len(its) < 3:
    try:
        x = int(input("enter the number: "))
        print("your input is: " + str(x))
        its.append(x)
    except (SyntaxError, ValueError):
        print("not gonna work, try again")
Omari Celestine
  • 1,405
  • 1
  • 11
  • 21