0

Ok need to understand why my code is not working. At the moment it's getting stuck in a infinite loop of asking the user for a pin after a wrong pin is inputted.

I believe I'm screwing up the while statement somehow.

def inputValidator():
    userInput = requestInteger("Please input a PIN between 1 - 1000")
    while 1 > userInput > 1000 : 
        requestInteger("Your PIN is not within 1 - 1000, please try again")
    print("Thanks! your new PIN is " + str(userInput))

thanks for the help guys!

0

3 Answers 3

2

Try this:

def inputValidator():
    userInput = requestInteger("Please input a PIN between 1 - 1000")
    while userInput<1 or userInput>1000:
        userInput = requestInteger("Your PIN is not within 1 - 1000, please try again")
    print("Thanks! your new PIN is " + str(userInput))

You'll want a new input from your user if userInput is smaller than 1 or bigger than 1000 - and like @Polina F. said - you didn't assign a new value to userInput inside the while loop. This is why it loops for ever.

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

Comments

1

You don't assign nothing in the while loop. userInput never gets updated - hence you can't exit the loop

Comments

1

you aren't assigning requestInteger to userInput

while 1 > userInput > 1000 : 
  userInput =requestInteger("Your PIN is not within 1 - 1000, please try again")

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.