0

As quite a novice to python, I am trying to make sure that my code does not bring up error messages.

The program in question I am coding will ask a user for a sentence (no punctuation) and will ask the user for a specific word that it would search the sentence for that particular word and inform the user as to which positions said word occurs in.

sentence= input("Enter a sentence")
lower = sentence.lower()
keyword= input("Input a keyword from the sentence")
twolower= keyword.lower()
words = lower.split(' ')
for (i, subword) in enumerate(words):
    if (subword == twolower): 
        print(i+1)

I am quite confused as to how to make this program so :

  • When the program asks for a sentence and nothing is inputted, it prompts the user to input again.
  • When the program asks for a sentence and an unfamiliar character is inputted (punctuation, numbers), it prompts the user to input again.

Could you guys please help? Thanks In advance

  • Take a look at [this SO post](http://stackoverflow.com/questions/23294658/asking-the-user-for-input-until-they-give-a-valid-response) – zehnpaard Nov 08 '15 at 22:17

1 Answers1

0

The first thing can be done like this:

while sentence == "":
  sentence= input("Enter a sentence")
ricpacca
  • 800
  • 6
  • 9