-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
5
  • What is Passlimit? Commented Jun 26, 2017 at 11:40
  • Possible duplicate of Beginner python loop Commented Jun 26, 2017 at 11:41
  • The limit to how many characters the password could be Commented Jun 26, 2017 at 11:41
  • Why is while Passlimit: indented more than Passlimit = 10 ? Commented Jun 26, 2017 at 11:44
  • Possible duplicate of Asking the user for input until they give a valid response Commented Jun 26, 2017 at 11:46

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.