Объясните, почему код не работает, когда слова нет в тексте!? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Объясните, почему код не работает, когда слова нет в тексте!?

https://code.sololearn.com/cheI6gj2aQbE/?ref=app

15th May 2022, 12:20 PM
Corn
2 Answers
0
index() raises an error when the search item is not found. You would need to catch this error. You could use the find() method, it will return -1 when the item is not found. The you would if to check if text.find(word) != -1
15th May 2022, 12:28 PM
Lisa
Lisa - avatar
0
когда слова нет в тексте, возникает исключение. поэтому программа перестает выполняться из-за этой ошибки. you can try just as if word in text :
15th May 2022, 12:28 PM
Jayakrishna 🇮🇳