[英]i am getting “internal check system error”
I have defined a variable in the program but it is not working.我在程序中定义了一个变量,但它不起作用。 The user will input the number to view animals and enter "exit" to end the program.
用户将输入数字查看动物并输入“退出”以结束程序。 The program will run in a loop.
程序将循环运行。
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
This will work.这将起作用。 Your list elements should be in string format " "
您的列表元素应该是字符串格式“”
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"]
In python , every string value should be written inside double or single quotes在 python 中,每个字符串值都应该写在双引号或单引号内
In your code , your list elements were not in quotes.在您的代码中,您的列表元素不在引号中。
But yes , its possible to have a list like yours.但是,是的,有可能有一个像你这样的清单。 But then the python recognizes these as variables
但是随后python将这些识别为变量
From the code you have given , it is understandable that these variables are not assigned a value before从您给出的代码中,可以理解这些变量之前没有赋值
Thus you got the variable error因此你得到了变量错误
You have to take input inside the while loop otherwise it will continue printing, and you cannot able to input next time你必须在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.