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

标签 python python-idle

我创建了一个列表,并且让用户能够选择他想要运行的方法。然而,当用户选择一个数字时,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)

这是输出

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

>

总是在我输入号码后停止。我显然不太了解python

最佳答案

您需要转换为整数:

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

关于Python 空闲 : how to run the whole script as it is always stopping at some point,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28467041/

相关文章:

python - 加载自定义 gstreamer 插件会引发 gst.ElementNotFoundError

Python Pandas - 格式化日期时间索引

Python IDLE 不会显示文档字符串

python - 如何中断 Python 中的命令执行?

python - 如何更改 IDLE 中的完成延迟?

python - 如何缩放基于 FFT 的互相关,使其峰值等于 Pearson's rho

python - 在阿拉伯语中查找两个子字符串之间的字符串

python - 当变量很多时如何进行智能数据分析

python - 如何从 Mac OSX 终端运行 argv 脚本