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