【发布时间】:2016-02-05 16:20:31
【问题描述】:
我希望我的代码运行,以便如果条件不满足(在 if 循环中),它将返回到代码的开头,要求用户输入另一个句子。我如何添加这个嵌套循环(如果这就是它的名字)?
sentence = input("Please input a sentence: ")
word = input("Please input a word: ")
sentence = sentence.lower()
word = word.lower()
wordlist = sentence.split(' ')
print ("Your word, {0}, is in positions:".format (word))
for position,w in enumerate(wordlist):
if w == word:
print("{0}".format(position+1))
【问题讨论】:
标签: python string loops nested