Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python PyCharm错误-名称';小鸡';可以是未定义的_Python_Pycharm_Jetbrains Ide - Fatal编程技术网

Python PyCharm错误-名称';小鸡';可以是未定义的

Python PyCharm错误-名称';小鸡';可以是未定义的,python,pycharm,jetbrains-ide,Python,Pycharm,Jetbrains Ide,我正在学习Python并遵循了一系列教程,然后我编写了自己的Python代码,询问你喜欢什么动物,如果你有,它的年龄,它的名字,我在PyCharm上遇到了这个错误。名称“chicks”可以是未定义的 我只有7岁,所以如果我错过了什么,请对我放松,下面是我的代码: # variables animal = input("What animal do you like? ") animal_array = ["Chicks", "chicks"] chicks_array = ["Yes", "ye

我正在学习Python并遵循了一系列教程,然后我编写了自己的Python代码,询问你喜欢什么动物,如果你有,它的年龄,它的名字,我在PyCharm上遇到了这个错误。名称“chicks”可以是未定义的

我只有7岁,所以如果我错过了什么,请对我放松,下面是我的代码:

# variables
animal = input("What animal do you like? ")
animal_array = ["Chicks", "chicks"]
chicks_array = ["Yes", "yes"]
other_animals = [""]
yes_answer = ["Yes", "yes"]
# if statements
if animal in animal_array:
    print("Me too!")
    chicks = input("Do you have a chick? ")

else:
    print("Ok")
    animal_q = input("Do you have a/an/some " + animal + "? ")


if chicks in chicks_array:
    chick_name = input("What is your chick's name? ")
    chicks_age = input("What is your chick's age? ")


else:
    print("Ended")
尝试在开头添加新变量“chicks”:

# variables
chicks = ''
animal = input("What animal do you like? ")
animal_array = ["Chicks", "chicks"]
chicks_array = ["Yes", "yes"]
other_animals = [""]
yes_answer = ["Yes", "yes"]
这样,即使你没有说你有一只小鸡,变量仍然是被定义的


享受学习python的乐趣

这个问题是因为当
if animal in animal_array:
的计算结果为false时,
雏鸡
从未定义。