Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I provide error checking to ensure user input only allows letters and provides a looping error message if numbers are typed?

Tags:

python

I am trying to provide a looping error message to the user for the customerName input so that the user receives an error message if they type anything other than letters aA - zZ,(I don't want to allow the user to input numbers specifically). I would like it to operate similar to the one I used for the customerAge input( which i provided as an example). but I cant seem to figure out the correct code to accomplish this. can anyone provide some insight?

customerName = input('Enter your name: ')

customerAge = int(input('Enter your age: '))
while customerAge <= 15 or customerAge >= 106:
    print('Invalid entry')
    customerAge = int(input('Enter your age: '))
like image 976
Chad Blodgett Avatar asked Nov 23 '25 17:11

Chad Blodgett


1 Answers

after reviewing all the answers I received (thanks goes out to all of you for the help). I coded it like this and it appears to be operating correctly.

customer_name = input('Please enter your name: ')
while not customer_name.isalpha():
    print('invalid Entry')
    customer_name = input('Please enter your name: ')
like image 118
Chad Blodgett Avatar answered Nov 26 '25 08:11

Chad Blodgett