-2

All the logic of the program is okay, the program takes the user input and prints an error if the user inputted anything other than a integer, but im not sure how to get the program to loop if the user enters an invalid input.

Passlimit = 10


    while Passlimit:
        try:
           Passinput = int(raw_input("how many characters and numbers would you like for your password to contain? NO LONGER THAN 10 CHARACTERS:   "))
           if not (Passinput <= Passlimit):
               raise ValueError()
        except ValueError:
            print("Invald input, Please only input numbers")
        else:
            print("NUMBER SELECTED")
        break
Soarino
  • 3
  • 1

1 Answers1

0

The break is immediately following the try...except...else clause. I think you meant to indent the break, so that it is only executed in the else branch.

You would still need to add code though to keep track of the number of tries, otherwise it will loop indefinitely as long as the user provides invalid input.

Ruud de Jong
  • 744
  • 3
  • 11