Q9: The following are programs to control the Edison Robot. Explain the code line by line along with the final outcome.

(a) EdPy Program Code
```python
for x in range(360):
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 1)
Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_5, 1)
```

(b) EdPy Program Code
```python
for i in range(4):
Ed.PlayBeep()
Ed.TimeWait(1, Ed.TIME_SECONDS)
```

Answer :

Let's break down the given EdPy program codes for the Edison Robot line by line and understand the final outcome for each.

Program (a)

for x in range(360):
Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 1)
Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_5, 1)

  • Line 1: for x in range(360):

    • This line initializes a loop that will run 360 times. The variable x takes on values from 0 to 359 (inclusive) throughout the loop iterations.
  • Line 2: Ed.Drive(Ed.FORWARD, Ed.SPEED_5, 1)

    • Within each iteration of the loop, the Edison Robot will move forward. Ed.FORWARD indicates the direction, Ed.SPEED_5 sets the speed, and 1 specifies the duration or distance for which the robot drives forward.
  • Line 3: Ed.Drive(Ed.SPIN_LEFT, Ed.SPEED_5, 1)

    • After moving forward, the robot will spin or turn left. Ed.SPIN_LEFT specifies the type of movement, Ed.SPEED_5 again controls the speed, and 1 determines how long or by how much the robot spins.

Final Outcome:

The combination of moving forward and then spinning left 360 times results in the robot tracing out a small circle as it continuously makes slight left turns while moving forward.

Program (b)

for i in range(4):
Ed.PlayBeep()
Ed.TimeWait(1, Ed.TIME_SECONDS)

  • Line 1: for i in range(4):

    • This loop will run four times, assigning the variable i values from 0 to 3 during the iterations.
  • Line 2: Ed.PlayBeep()

    • This command makes the Edison Robot emit a beep sound once during each iteration.
  • Line 3: Ed.TimeWait(1, Ed.TIME_SECONDS)

    • After the beep, this line causes the program to pause for 1 second before continuing to the next loop iteration.

Final Outcome:

The robot will beep four times in total, with a 1-second pause between each beep. This creates an