design, write and debug programs that accomplish specific goals, including controlling or simulating physical systems; solve problems by decomposing them into smaller parts.

use logical reasoning to explain how some simple algorithms work and to detect and correct errors in algorithms and programs

5.5a

LO: To solve problems using conditional statements. (2)

Let's look at a new world called Apple1, you can see that Reeborg has to collect two apples and then reach the goal/home.

We can solve this world by using our while and if statements:


while not at_goal():
    if object_here():
        take()
    else:
        move()
else:
    done()

			

Now we're going to look at the world Apple2, we now have an additional problem - a wall to deal with!

Have a go at writing the code for this problem, test it and debug it if necessary.*



Some advice:

Remember to save any incorrect attempts for debugging.

Once you code works, try it on the world Apples to see if Reeborg can complete it - is there anything you need to add?





* Solutions can be found in the code examples below.

Code Examples

Resources