Loop Control: Break

https://www.codecademy.com/courses/learn-python-3/lessons/learn-python-loops/exercises/break

dog_breeds_available_for_adoption = ["french_bulldog", "dalmatian", "shihtzu", "poodle", "collie"]

dog_breed_I_want = "dalmatian"

for dog_breed in dog_breeds_available_for_adoption:

  print(dog_breed)

  if dog_breed == dog_breed_I_want:

    print ("They have the dog I want!")

    break

So the question is "Inside your for loop, after you print each dog breed, check if the current element inside dog_breed is equal to dog_breed_I_want . If so, print `“They have the dog I want!” "

When I run the code I get the displayed text that I want but " Are you printing out “They have the dog I want!” if the dog_breed exists in the list? " shows up. I think there might be some formatting issue or something where I’m not exactly writing the code how it wants me to but I can’t find where. Any ideas?

I couldn’t see anything wrong with it so tried running your code in the lesson.

I’m guessing it’s just something weird with how the checks run, if you remove the space between your print and ("They have the dog I want!") the code passes.

Though the code works with the space, I don’t believe it’s the standard way to write it, so could be a good point to take away from this :smile:

2 Likes

ah you’re right, I usually don’t write it with the space and I see I did make a mistake there. Thank you!

2 Likes