0

I'm fairly new to Python and I'm using a while True loop. Inside that loop I have

Sentence= input("please enter a sentence").lower().split()

However I want to create validation so an error message appears when the user inputs a number instead of a letter. I was researching and saw the use of .isalpha. Would anyone where this would go in the whie true loop to create and error message for inputting numbers?

Moses Koledoye
  • 77,341
  • 8
  • 133
  • 139
Codee
  • 1
  • 1

2 Answers2

1
sentence = input("please enter a sentence").lower().split()
for word in sentence:
    if not word.isalpha():
        print("The word %s is not alphabetic." % word)
John Gordon
  • 29,573
  • 7
  • 33
  • 58
  • Thank you I completely get it! Is there a way to keep repreating the question until letters are inputted? – Codee Sep 19 '16 at 15:15
0

Something like this?

sentence = input("please enter a sentence: ").lower().split()

while False in [word.isalpha() for word in sentence]:
    sentence = input("Do not use digits. Enter again: ").lower().split()
nauer
  • 690
  • 5
  • 14