Bird
0
0

What will the following code print if sensor_value is 60 and threshold is 60?

medium📝 Predict Output Q5 of 15
Raspberry Pi - Automation and Scheduling
What will the following code print if sensor_value is 60 and threshold is 60?
sensor_value = 60
threshold = 60
if sensor_value >= threshold:
    print('Threshold reached')
else:
    print('Below threshold')
AThreshold reached
BBelow threshold
CNo output
DRuntime error
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate the condition sensor_value >= threshold

    60 is equal to 60, so condition is True.
  2. Step 2: Identify which print statement executes

    Since condition is True, 'Threshold reached' is printed.
  3. Final Answer:

    Threshold reached -> Option A
  4. Quick Check:

    Condition True when equal = prints 'Threshold reached' [OK]
Quick Trick: >= includes equal values for alert [OK]
Common Mistakes:
MISTAKES
  • Thinking equal fails condition
  • Ignoring else block
  • Assuming error on equal

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes