Conditionals in Action¶

Lab 6¶

  • scurry
    • Lots of nested if, and a triple or. What solutions did they come up with?
  • paint-and-exit
    • Like paint-the-box, there are various ways to do this.
      • Did they do it the same as paint-the-box, or a different way?
    • How did they get out?
      • Two while? while + if?

Over the Mountain¶

hike.py¶

</div>

Bit needs to hike over the mountain.

Paint only the squares directly above a blocked square.

NOTES

Look at both inputs to assess the requirements. Do we need a while loop for climbing, as opposed to a hard coded number of move statements? How do we know?

How do we break this problem up? What are the patterns that we see? Are there elements of event stream or mosaic in this problem? Are there natural subproblems, like we had with treasure.py a moment ago?

Treasure! 🧑🏻‍🎨¶

treasure.py¶

To reach the cave, Bit must follow these instructions:

  • Turn right on blue squares.
  • Turn left on red squares.

Once in the cave, navigate through the passage to the treasure (red square).

Paint the path followed green.

NOTES

Break the problem up into get-to-the-cave and find-the-treasure.

The flying has move, paint, and turn statements. What order is necessary?

  • the paint step can clobber the turn step.

Finding the treasure involves a nested if. It's essentially the same logic as scurry.py from lab 6.

Key Ideas¶

  • Break big problems into smaller problems
  • Nested if blocks