Question
a) There are four errors in the following program that will prevent it from running as intended. For each error, state what the error is
a) There are four errors in the following program that will prevent it from running as intended. For each error, state what the error is and give the correct Python statement.
1 %%sim_magic -b Coloured_bands 2 # Drive Forward and Stop at Pure Green Line 3 4 # 5 from ev3dev2.motor import MoveSteering, OUTPUT_B, MOTOR_C 6 from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4 7 from ev3dev2.sensor.lego import ColorSensor 8 9 # 10 colorLeft = ColorSensor(INPUT_2) 11 12 # 13 steering_drive = MoveSteering(OUTPUT_B, OUTPUT_C) 14 steering_drive.on(direction, 20) 15 16 # 17 if colorLeft.rgb[0]==0 and colorLeft.rgb[1]==1 and colorLeft.rgb[2]==0: 18 print('Left RGB: ' + str(colorLeft.rgb)) 19 20 # Explicitly stop motors at end of program 21 steering_drive.off()
b) What is a comment in a computer program? For each of the four empty comments in the program above, provide a meaningful comment that describes the action of the program.
c) .For this part of the question, use the version of the program you corrected in part (a).
i. Give an example of a conditional statement in this program. ii. State two forms of loop that can be used in a Python program. How can the program flow escape a loop and continue to the next part of the program? iii. State one way, other than correcting the errors or adding comments, in which the original program in part (a) could be improved.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started