strong text when i run this code it still shows up with the "search unsuccessful" message, could anyone help me figure out why? my code. I know that it has a loop in it but i cannot figure out how to make the code stop looping once it has found all of the positions of the word in the sentence.
sentence= "the hat ran away from the cat"
print(sentence)
word_to_find= input("write word from sentence")
senLow= sentence.lower()
word= word_to_find.lower()
senList= senLow.split()
for pos in range(len(senList)):
if word== senList[pos]:
print(word, "found in position:", pos+1)
else :
print ("search unsuccessful")
Aucun commentaire:
Enregistrer un commentaire