Ex 36 Attempt at own game. Having problem

I don’t think I understand when a list is properly updated during a while statement. When I update list during a nested if statement, the overarching while statement doesn’t seem to respond properly.
I will attach my code but it is quit long. I took this exercise a little too far and now I can’t seem to get past it. Maybe I will return later.

The issue specifically is when an animal is chosen to cross the river with my if statement for checking that you didn’t leave the chicken with the grain or fox with chicken is tripped every time, even if you didn’t. So I am imagining the list that they belong to isn’t being properly updated.

ex36 fox, chicken, grain

this is a mess. I need to work on it more before sharing

Okay it is ready now. Would be buch more efficient with dictionary or some other data type but because as of ex35 they haven’t been learned, I haven’t used them.

So, if you have a situation where you’re doing something like:

for x in list_of_stuff:
   list_of_stuff.append("x")

You’ll run into trouble. Last I checked python really doesn’t like this since it changes the list being processed while it’s being processed.

But, you say you’re using a while loop, so either you’re running into the same problem just in while-loop form, or you’re doing something different. If this is still a problem then boil the problem code down into a sample snippet that causes the problem and post here so I can take a look. Doing that might also help you find the problem.

1 Like

I appreciate your responses. The forum is a funny place for me to update issues I have because I end up fixing them in a weird way before I can come back to the forum. In this example I can’t even remember what my problem was. Now I am on the Gothan exercise I finding myself wanting to go back and adapt my ex36 game with the new skills I have learned but am not at a skill level that allows me to know for what each skill is best applied. I do appreciate the response though!

A free service run by Zed A. Shaw for learncodethehardway.org.