简体   繁体   English

Python IDLE:如何运行整个脚本,因为它总是在某个时刻停止

[英]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. 但是,当用户选择一个数字时,不会执行if else语句。 Does anyone know why is that ? 有人知道为什么吗? I am new to IDLE and python. 我是IDLE和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 我们的列表是:['hello','bonjour','hola','ohayo','hello'] 1个计数,2个列表,3个反向,4个查找,5个插入,请调用所需的函数执行:1

> >

always stopping after I put the number. 输入号码后总是停下来。 I am obviously not understanding python well 我显然不太了解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