Pet Quiz - Strange Quirk on Questions/Answers

I finished Pet Quiz with something I found weird.

Here’s my code:

def petSay(event):
    pet.say("Yes.")
    pet.say("No.")
    pet.say("3,000 years old.")
    pet.say("Yes, it's okay.")
    pet.say("Only if I'm made High Executor.")

pet.on("hear", petSay)

hero.say("Do you understand me?")
hero.say("Are you a cougar?")
hero.say("How old are you?")
hero.say("Have you understood our culture?")
hero.say("Will you join our army?")

I was able to successfully finish this level by this weird, strange quirk. My code is perfect. It worked for each and every topic issued by my hero, Anya, to the cougar.

However, the cougar would respond with only the first and second answers: yes and no. As the questions started popping up from Anya, the cougar only responds with just the first two answers. It could not answer the age-related question, the culture, and the recruitment into the army.

I’m wondering what I did wrong, lol.

1 Like

With the dozen years of development experience, I can’t say the same about my code :wink:

Look, petSay is called each time when the pet hears something. Each time it starts from the beginning. To be more correctly you have 5 called the function in the same time, and your pet tries to say many phrases, but last ones are in priority.

Haha, I can understand that. Sometimes, it is frustrating to see that the code is actually written the way it is written but doesn’t perform as expected. Though I do understand that petSay() had different statements, I would naturally assume that when the pet “hears”, it doesn’t hear anything else except the hero “asking” the questions.

I guess no code is perfect but at the time, I felt that it was perfect.