'How to accept number and not prompt for another 4 digit code even if number is below 10000
This is where the Issue happens. Even if the pin is under 4 digits(10000) the second pin input will still run.
print("Hello")
print('Please type your username')
username = input('Place Here:')
print('Please type your secure 4 digit pin for our system')
pin = int(input('Place Here:'))
if pin >= 10000:
print("Sorry, I didn't understand that. Please try again. 4 digits only")
pin=int(input('Place Here:'))
print('Please provide your name under your registered account')
name = input('Place Here:')
print('Welcome', name, 'you are now logged into White Rock')
print('If you are interested in seeing your username or pin, please type Yes, or No')
question = input("Pace yes or no here:")
if question =='Yes' or question == 'yes':
print(username)
print(pin)
elif question == 'No' or question =='no':
print('Not needed, ok.')
Solution 1:[1]
How about:
if len(str(pin)) != 4:
instead of:
if pin >= 10000:
... you may still make this in a little loop and abort after x invalid attempts.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TobsterJ |
