My goal is to make sure when the user types in numbers in the userName input, then it should not accept it and make them try again.
Same thing with userNumber. When a user types in letters, they should be prompted with another line telling them to try again.
The problem is that when they do type in the correct input, the program will continue looping and listing the numbers indefinitely.
I'm new to coding, and I'm trying to figure out what I'm doing wrong. Thank you in advance!
userName = input('Hello there, civilian! What is your name? ')
while True:
if userName.isalpha() == True:
print('It is nice to meet you, ' + userName + "! ")
else:
print('Choose a valid name!')
userNumber = input('Please pick any number between 3-100. ')
while True:
if userNumber.isnumeric() == True:
for i in range(0,int(userNumber) + 1,2):
print(i)
else:
print('Choose a number please! ')
userNumber = input('Please pick any number between 3-100. ')
Alternative way: use a condition in your
while
loops.