我正在学习Python,接着是Tech with Tim的一系列教程,然后我编写了自己的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”:
这样,即使你没有说你有一只小鸡,变量仍然是被定义的
享受学习python的乐趣
相关问题 更多 >
编程相关推荐