作为python的新手,我正在尝试确保我的代码不会显示错误消息。
我正在编码的程序会询问用户一个句子(没有标点符号),并会询问用户一个特定的单词,它会在该句子中搜索该特定单词并告知用户该单词的位置发生在。
sentence= input("Enter a sentence")
lower = sentence.lower()
keyword= input("Input a keyword from the sentence")
twolower= keyword.lower()
words = lower.split(' ')
for (i, subword) in enumerate(words):
if (subword == twolower):
print(i+1)
我对如何制作这个节目非常困惑:
答案 0 :(得分:0)
首先可以这样做:
while sentence == "":
sentence= input("Enter a sentence")