my code: < /p>
Код: Выделить всё
sentence = "please write a program which keeps asking the user for words"
index = 0
substring = sentence.find(" ")
while index < len(sentence):
substring = sentence.find(" ")
sentence = sentence[substring+1:]
index += 1
print(sentence)
< /code>
Этот код работает, когда предложение: < /p>
sentence = "it was a dark and stormy python"
< /code>
Но это не работает, когда предложение: < /p>
sentence = "please write a program which keeps asking the user for words"
Я ожидаю, что код выведет последнее слово в предложении.
Подробнее здесь: https://stackoverflow.com/questions/797 ... -in-a-loop