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