Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to increment the production counter by 1 each time the sensor detects a product.
PLC Programming
if sensor_triggered: production_counter [1] 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-=' which would decrease the counter.
Using '*' or '/' operators which do not increment the count.
✗ Incorrect
The '+=' operator adds 1 to the current value of production_counter, increasing the count each time a product is detected.
2fill in blank
mediumComplete the code to reset the production counter when the reset button is pressed.
PLC Programming
if reset_button_pressed: production_counter [1] 0
Attempts:
3 left
💡 Hint
Common Mistakes
Using '+=' which adds to the current value instead of resetting.
Using '-=' or '*=' which modify the value incorrectly.
✗ Incorrect
The '=' operator assigns the value 0 to production_counter, resetting the count.
3fill in blank
hardFix the error in the code that checks if the production counter reached the target count.
PLC Programming
if production_counter [1] target_count: stop_production()
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which causes a syntax or logic error in condition.
Using '!=' which checks for inequality, not equality.
✗ Incorrect
The '==' operator compares production_counter to target_count to check if they are equal, which is needed for the condition.
4fill in blank
hardFill both blanks to create a condition that increments the counter only if the sensor is triggered and the system is running.
PLC Programming
if sensor_triggered and system_status [1] 'running': production_counter [2] 1
Attempts:
3 left
💡 Hint
Common Mistakes
Using '!=' which checks for inequality instead of equality.
Using '-=' which decreases the counter instead of increasing.
✗ Incorrect
The '==' operator checks if system_status equals 'running', and '+=' increments the counter by 1 when both conditions are true.
5fill in blank
hardFill all three blanks to create a dictionary that maps product IDs to their counts, including only products with counts greater than zero.
PLC Programming
product_counts = { [1]: [2] for [3], [4] in products if [4] > 0 }Attempts:
3 left
💡 Hint
Common Mistakes
Mixing keys and values incorrectly.
Using the wrong variable in the condition.
✗ Incorrect
The dictionary comprehension uses 'product_id' as keys and 'count' as values, filtering only counts greater than zero.
