Я пытаюсь создать программу, которая при вводе предложения запрашивает слово для поиска и сообщит вам, где в предложении встречается следующий код:
loop=1
while loop:
sent = str(input("Please type a sentence without punctuation:"))
lows = sent.lower()
word = str(input("please enter a word you would want me to locate:"))
if word:
pos = sent.index(word)
pos = pos + 1
print(word, "appears at the number:",pos,"in the sentence.")
else:
print ("this word isnt in the sentence, try again")
loop + 1
loop = int(input("Do you want to end ? (yes = 0); no = 1):"))
Кажется, он работает нормально, пока я не наберу его неправильно, например, привет, меня зовут Уилл, и слово, которое я хочу найти, вместо «извините, этого не происходит в предложении», но на самом деле ValueError: подстрока не найдена
Я честно не знаю, как это исправить, и мне нужна помощь.
try/except ValueError
. - person Jean-François Fabre   schedule 12.01.2017