Q:

Validating that input consists of alphabetical characters

I have been trying to add some validation for users entering a new word to a text file.
The input must consists of letters only and I have got this working using if statements with .isalpha(), however I wanted to try and see if I could get it working using try, except and so far I have not got it working.
The try statement is allowing all input in no matter if it contains digits or spaces. I cant seem to spot where i've gone wrong.
def AddNewWords():
    List = []
    Exit = False
    while not Exit:
        choice = input("Please enter a word to be added to the text file: ")
        try:
            choice.isalpha()
        except:
            print("Not a valid word")
            continue
        else:
            List.append(choice)
            Exit = True
   Return List

AddNewWords()

A:

isalpha() returns True/False, it doesn't raise any exception.
Try this instead:
choice = input("Please enter a word to be added to the text file: ")
if not choice.isalpha():
    print("Not a valid word")
    continue
List.append(choice)
Exit = True

FWIW, you can also rewrite your loop in a more compact way without using the exit variable, but rather while True + break:
while True:
    choice = input("Please enter a word to be added to the text file: ")
    if choice.isalpha():
        List.append(choice)
        break
    print("Not a valid word")

