1
我創建了一個列表,並且我爲用戶提供了選擇他希望運行的任何一種方法的能力。但是,當用戶選擇一個數字時,if else語句不會被執行。有誰知道這是爲什麼?我是新來的IDLE和Python。Python IDLE:如何運行整個腳本,因爲它總是停在某個點
這是我的代碼
aList = ['hello','bonjour','hola','ohayo','hello'];
print("our list is: ", aList)
print("1-count, 2-inList, 3-Reverse, 4-find, 5-insert")
choice = input("please call the function you want to execute: ")
if choice == 1:
word = input("which word would you like to count? ")
print(aList.count(word))
elif choice == 2:
inList = input("which word would you like to check if it's in the list")
if inList in aList:
print(True)
else :
print(False)
elif choice == 3:
for i in reversed(aList):
print(i)
elif choice == 4:
item = input("what item would you like to find?")
aList.index(item)
elif choice == 5:
item = input("what would you like to anwser? ")
aList.insert(item)
,這是輸出
我們的名單是: '你好', '卓悅', 'HOLA', 'OHAYO', '你好' ] 1計數,2- INLIST,三反,4-發現,5-插入請撥打 功能要執行:1
>
總是停藥後我把號。我顯然不理解蟒蛇以及
因爲'「1」 = 1' ...查看http://stackoverflow.com/q/28457422/ 3001761或成千上萬個其他類似問題中的任何一個。 – jonrsharpe 2015-02-12 00:09:23