繁体   English   中英

我收到“内部检查系统错误”

[英]i am getting “internal check system error”

我在程序中定义了一个变量,但它不起作用。 用户将输入数字查看动物并输入“退出”以结束程序。 程序将循环运行。

animals = [camel, lion, deer, goose, bat, rabbit]
x = input("Please enter the number of the habitat you would like to view: ")
while True: 
    if x != ("exit"):
         print(animals[(int(x))])
    else: x == ("exit")
    print("See you later!")
exit

这将起作用。 您的列表元素应该是字符串格式“”

animals = ["camel","lion","deer", "goose", "bat", "rabbit"]
x = int(input("Please enter the number of the habitat you would like to view: "))
while True: 
    if x != ("exit"):
         print(animals[x])
         break
    elif (x == ("exit")):
        print("See you later!")
animals = ["camel", "lion", "deer", "goose", "bat", "rabbit"]

在 python 中,每个字符串值都应该写在双引号或单引号内

在您的代码中,您的列表元素不在引号中。

但是,是的,有可能有一个像你这样的清单。 但是随后python将这些识别为变量

从您给出的代码中,可以理解这些变量之前没有赋值

因此你得到了变量错误

你必须在while循环内输入,否则它会继续打印,你下次不能输入

animals = ["camel", "lion", "deer", "goose", "bat", "rabbit"]
while True:
    x = input("Please enter the number of the habitat you would like to view: ")
    if x != ("exit"):
         print(animals[(int(x))])
    else:
        x == ("exit")
        print("See you later!")
        break

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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