简体   繁体   中英

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

I created a list, and I offered the user the ability to choose whichever method he would like to run. However when the user selects a number, the if else statements are not being executed. Does anyone know why is that ? I am new to IDLE and python.

this is my code

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)

and this is the output

our list is: ['hello', 'bonjour', 'hola', 'ohayo', 'hello'] 1-count, 2-inList, 3-Reverse, 4-find, 5-insert please call the function you want to execute: 1

>

always stopping after I put the number. I am obviously not understanding python well

您需要转换为整数:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM