Reeborg’s compass is broken; he can use it to determine if he is facing North using facing_north(), but that’s it.
When we introduced return in a previous tutorial we saw how we could define a test so that Reeborg could determine if he was facing South, using the following:
def is_facing_south(): turn_left() turn_left() remember = is_facing_north() turn_left() turn_left() return remember # now, ensure that Reeborg is facing South while not is_facing_south(): turn_left()
Define a method is_facing_North by replacing pass by the appropriate lines of code.
class RepairedRobot(UsedRobot): def is_facing_south(self): pass reeborg = RepairedRobot(3, 3) while not reeborg.is_facing_south(): reeborg.turn_left()
Reeborg should not turn on the screen as it determines its direction.
Instead of doing a left turn using reeborg.turn_left(), change the value of the orientation prior to using remember = is_facing_north()
Do it another way!
Do even more!
Implement the methods is_facing_east() and is_facing_west(). Make sure to test them by running some programs that make use of them.
If Reeborg’s compass is fixed, it means that Reeborg should be able to orient itself rapidly to face any direction as required.
Design four methods, one for each direction starting with face_north() which will have Reeborg turn immediately to face the required direction in a single step. Make sure that you record that step as a “frame”. You do not have to worry about the appearance of the oil leak.