Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to turn on the red light.
PLC Programming
IF sensor_detected THEN
[1] := TRUE;
END_IF;Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong light variable like GreenLight or YellowLight.
Forgetting to set the variable to TRUE.
✗ Incorrect
The red light variable must be set to TRUE to turn on the red light when the sensor is detected.
2fill in blank
mediumComplete the code to wait for 5 seconds before changing the light.
PLC Programming
Timer(IN := TRUE, PT := T#[1]s); IF Timer.Q THEN ChangeLight(); END_IF;
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong time value like 3 or 10 seconds.
Not including the 'T#' prefix for time.
✗ Incorrect
The timer must be set to 5 seconds to wait that long before changing the light.
3fill in blank
hardFix the error in the code to turn off the green light.
PLC Programming
GreenLight := [1];Attempts:
3 left
💡 Hint
Common Mistakes
Setting the variable to TRUE or 1 instead of FALSE.
Using 0 which may not be valid in this context.
✗ Incorrect
To turn off the green light, set its variable to FALSE.
4fill in blank
hardFill both blanks to check if the yellow light is on and then turn on the red light.
PLC Programming
IF [1] = TRUE THEN [2] := TRUE; END_IF;
Attempts:
3 left
💡 Hint
Common Mistakes
Checking the wrong light in the condition.
Turning on the wrong light inside the IF.
✗ Incorrect
We check if YellowLight is TRUE, then set RedLight to TRUE to turn it on.
5fill in blank
hardFill all three blanks to create a dictionary mapping light colors to their status, including only lights that are on.
PLC Programming
LightStatus := { [1]: [2] for [3] in Lights if [2] = TRUE };Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names for keys or iteration.
Not matching the variable names consistently.
✗ Incorrect
We use 'color' as the key, 'Lights[color]' as the value, and iterate over 'color' in Lights to build the dictionary of lights that are on.
