PyCharm Error - Name 'chicks' can be undefined

Viewed 888

I am learning Python and followed a tutorial series by Tech with Tim and then I made my own python code that asks you what animal you like, if you have it, what age is it, what's its name and I got this error on PyCharm. Name 'chicks' can be undefined.

I am only 7 so if I missed something take it easy on me and heres my code below:

# 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")
1 Answers

Try adding a new variable "chicks" at the beginning:

# variables
chicks = ''
animal = input("What animal do you like? ")
animal_array = ["Chicks", "chicks"]
chicks_array = ["Yes", "yes"]
other_animals = [""]
yes_answer = ["Yes", "yes"]

That way, the variable is still defined even if you don't say that you have a chick.

Have fun learning python!

Related