Instruction
Good job! Now we'll write a code which will pick a random move for a robot.
In each round, a robot can do one of the following:
- Turn right
- Move forward
- Shoot a laser beam
We'll implement those moves later on, but we can write code to simulate them now.
Exercise
- Create a function named
act_robot(robot). The function should first pick a random number from 0 to 2 (see the Hint if you don't know how to generate a random number in Python). Based on the number picked, the function will make the robot turn right, shoot a laser beam, or move forward. We don't have these methods implemented yet, so for now we'll just print simple statements to the output:- For the random number 0, print the entire
robotargument and add the word "right" after a space, e.g.{'name': 'B', 'direction': '<'} right - If the number is 1, print
robotand "laser shoot" after a space. - If the number is 2, print
robotand "move forward" after a space.
- For the random number 0, print the entire
- Create the
play_round(robot_a, robot_b)function. Inside the function, invoke theact_robot(robot_a)function and theact_robot(robot_b)function (in that order).
Stuck? Here's a hint!
To pick a random number from 0 to 2, use the following invocation:
action = random.randint(0, 2)



