0

Trying to accept only text as input in my program, this is a snippet where I'm having trouble.

def askStr(th):
try:
   a = str(input(th))
except ValueError:
    raise ValueError("You may only enter a string (letters.)")
if "1" or "2" or "3" or "4" or "5" or "6" or "7" or "8" or "9" in a:
    raise TypeError("No. Only enter letters.")
return a

When I enter a number, it raises the error as expected. BUT, when I enter anything else, only letters, it still gives me the error. No idea what to do here.

1 Answers1

0

Try this

def askStr(th):
   a = str(input(th))
   for c in a:
       if c in string.digits:
           raise TypeError("No. Only enter letters.")
   return a
Ardein_
  • 166
  • 6