Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Conditional if statements can be grouped within other if statements – sometimes

ID: 3673006 • Letter: C

Question

Conditional if statements can be grouped within other if statements – sometimes described as nested together. The internal conditions are not evaluated until the outer conditions are met. The program below uses those conditional statements to control the robot's actions as described by the answer options below.

Match the best descriptions for the actions of the robot given the light sensor readings shown below. Assume that the robot and the User-Defined Functions for motion are the same as those used in class; new functions are provided for the light sensors in the code below.

#include 11 include servo library servo servoLeft; IN Declare left servo Servo servoRight; UN Declare Right servo void setup () A / Built in initialization block servoRight. attach (30) : 1 / Attach right signal to pin 30 servoLeft . attach (31); / Attach right signal to pin 31 serial begin (9600) : // set data rate to 9600 bps leftForward (100); rightForward ( 100); void loop () int leftLightSensorvalue = getLeftLightsensor () ; int rightLightSensoralue = getRightLightsensor (); if ( leftLightSensorValue > 40 ) if (rightLightSensorValue > 54) leftBackward (100); rightBackward (100 ); else leftForward (100); rightBackward (100 ); else if ( leftLightsensorValue

Explanation / Answer

1. C ( Left light Sensor > 40 and right Light Sensor < 54 for first 25 sec , thus it spins to right for 25 sec and after that Left light sensor > 40 and right light sensor > 54 condition meet , thus it goes backward

2. B ( Left light sensor < 20 and Right light Sensor > 40 , thus it moves backward)

3. A ( for first 25 sec , it matches Left sensor > 40 and Right Sensor >54 , thus it goes backward for first 25 secs and spins to right)

4. D ( 2 reason - Well only this option left and second it doesn't satisfy any condition thus it keep doing what it was doing , keep moving forward )

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote