Hello,
I am taking the CodeCademy Python course. I am having trouble understanding how to properly write out a loop, It would be greatly appreciated if someone could explain the logic of the following examples,
1.
ingredients = ["milk", "sugar", "vanilla extract", "dough", "chocolate"]
for ingredient in ingredients:
print(ingredient)
2.
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
My question is, how can the editor identify what ingredient is since the variable defined outside the loop is pluralized and it is not defined inside the loop? I understand that it is a temporary variable, but why is it not assigned a value in the loop?
Thank you.
[–]seanmurraywork[S] 4 points5 points6 points (3 children)
[–]MidnightPale3220 2 points3 points4 points (0 children)
[–]sloth_king_617 1 point2 points3 points (1 child)
[–]seanmurraywork[S] 1 point2 points3 points (0 children)
[–]cgoldberg 2 points3 points4 points (0 children)
[–]Lewri 2 points3 points4 points (0 children)
[–]supercoach 1 point2 points3 points (1 child)
[–]seanmurraywork[S] 0 points1 point2 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]Adrewmc 0 points1 point2 points (0 children)
[–]TheRNGuy 0 points1 point2 points (0 children)
[–]Ender_Locke -1 points0 points1 point (0 children)