I need my program to validate the user input. So far I have defined a range of 'validLetters' and 'validNumbers':
validLetters = ('abcdefghijklmnopqrstuvwxyz ')
validNumbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
However, it should then validate like this:
name = input("What is your name?\n").lower()
while name == "" or name in validNumbers:
name = input("What is your name?\n").lower()
strinput0 = name
char_only0 = ''
for char in strinput0:
if char in validLetters:
char_only0 += char
name = char_only0
The problem lies with the 'in' part of the statement, it only works if the input is a single number (eg. '6'), but it accepts two or more numbers (eg. '65') because '65' (unlike '6') is not in validNumbers.
I want it to scan the entire input and ask again if it only consists of numbers, as you can see it takes these out (plus any special characters) at the end.
There are .isalpha() solutions, however, they don't allow whitespaces, which are required if the user inputs their full name!
I have been chipping away at this problem for hours know, someone out there is probably able to solve this for me. Thanks in advance.