Здравствуйте, поэтому мне нужно сделать программу, которая идентифицирует все позиции, где слово встречается в списке, но когда я запускаю свою программу, ничего не выводит. Вот мой код:Python Найти слово в списке
sentence =("ASK NOT WHAT YOUR CONTRY CAN DO FOR ASK WHAT YOU CAN DO FOR YOUR CONTRY") #This is a list
print (sentence)
text = input("Choose a word from the sentence above")#this prints out some text with an input
sentence = sentence.split(" ")# This splits the list
text = text.upper()# this makes the text in capital letters
def lookfor():
if text in sentence:
for i in sentence:
value = sentence.index(sentence)
print ("Your word has been found in the sentence at the position", value + "and", value)
else:
print ("The word that you have typed is not found in the sentence.")
Спасибо
Вы рассматривали вызов вашей функции? – timgeb
Или Googling для десятков других людей, обманывающих одну и ту же домашнюю работу? – jonrsharpe
и просто для уточнения, ваша переменная предложения на самом деле является кортежем, а не списком – glls