the code
i. The program listed below is based around the Grey_bands background. The program is intended to make the simulated robot drive forward over each grey band. When it drives into a new grey band, the robot will say aloud how many bands it has entered. You can download the code here. Modify this program to: 1. Use the Coloured_bands background. 2. Continue to drive over all of the bands. 3. Count aloud how many bands it has entered whenever it enters a non-white band. 4. Stop the robot after it drives forward over the black band. (10 marks) 1 %%sim_magic_preloaded --background Grey_bands -R # Program to count the bands aloud 2 2 3 4 4 # Start the robot moving tank_drive.on(SpeedPercent(15), SpeedPercent(15)) 5 6 7 # Initial count value 8 count = 0 9 10 # Initial sensor reading 11 previous_value = colorLeft.reflected_light_intensity_PC 12 13 # Create a loop 14 while True: 15 16 # Check current sensor reading 17 current_value = colorLeft.reflected_light_intensity_pc 18 19 20 21 22 23 # Test when the robot has entered a band if previous_value==100 and current_value < 100: # When on a new band: # - increase the count count = count + 1 # - display the count in the output window print(count) # . say the count aloud say(str (count)) 24 25 26 27 28 29 # Update previous sensor reading previous_value = current_value 30 ii. Try running the program you have written for part (i) using the Rainbow_bands background. If your program does not run correctly, outline what the issue is, and what you would have to change to make your program run. If your program does run correctly, outline how you have achieved this. Discuss whether your program would work on any banding of colours. (6 marks) iii. Provide one advantage of using Python functions when writing longer programs. Outline a Python function that prints out 'Hello World'.
%%sim_magic_preloaded --background Grey_bands -R # Program to count the bands aloud # Start the robot moving tank_drive.on(SpeedPercent(15), SpeedPercent(15)) # Initial count value count = 0 # Initial sensor reading previous_value = colorLeft.reflected_light_intensity_pc # Create a loop while True: # Check current sensor reading current_value = colorLeft.reflected_light_intensity_pc = # Test when the robot has entered a band if previous_value==100 and current_value < 100: # When on a new band: # - increase the count count = count + 1 # - display the count in the output window print(count) # - say the count aloud say(str (count)) # Update previous sensor reading previous_value current_value =
i. The program listed below is based around the Grey_bands background. The program is intended to make the simulated rob
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
i. The program listed below is based around the Grey_bands background. The program is intended to make the simulated rob
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!