1
因此,这里是我的代码:限制输入一个字
sentence=input('Please input a sentence: ').lower()
word=input('What word would you like to select? ').lower()
words=sentence.split()
for (A, keyword) in enumerate(words):
if(keyword==word):
print(A+1)
if(keyword!=word):
print ('This word is not in the sentence')
我需要将用户输入限制为只有一个字,如果他们输入2个字,如何将我去这个返回的错误信息?
我宁愿像'ValueError','Exception'太广 – user312016