That is reinventing the wheel, use str.isalpha
You could use assert
and AssertionError
from string import ascii_letters
value = None
while True:
try:
value = input("Give a value: ")
assert all(c in ascii_letters for c in value)
break
except AssertionError:
print("Invalid input, try again")
print("Valid input:", value)
Give a value: aa!
Invalid input, try again
Give a value: !!!
Invalid input, try again
Give a value: !
Invalid input, try again
Give a value: rrTT
Valid input: rrTT
0
solved Is it possible to avoid integers,floats and special characters using try-except statement only?