簡體   English   中英

Python IDLE:如何運行整個腳本,因為它總是在某個時刻停止

[英]Python IDLE : how to run the whole script as it is always stopping at some point

我創建了一個列表,並為用戶提供了選擇他想運行的任何方法的能力。 但是,當用戶選擇一個數字時,不會執行if else語句。 有人知道為什么嗎? 我是IDLE和python的新手。

這是我的代碼

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)

這是輸出

我們的列表是:['hello','bonjour','hola','ohayo','hello'] 1個計數,2個列表,3個反向,4個查找,5個插入,請調用所需的函數執行:1

>

輸入號碼后總是停下來。 我顯然不太了解python

您需要轉換為整數:

choice = int(input("please call the function you want to execute: "))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM