Bird
0
0

Why does this Raspberry Pi dashboard code fail?

medium📝 Debug Q7 of 15
Raspberry Pi - Web Server and API
Why does this Raspberry Pi dashboard code fail?
for i in range(5):
print(read_sensor())
Aread_sensor() is not called correctly
Brange(5) is invalid syntax
CMissing indentation inside the for loop
Dprint() cannot be used in loops
Step-by-Step Solution
Solution:
  1. Step 1: Check indentation rules in Python

    Code inside loops must be indented.
  2. Step 2: Verify other syntax elements

    range(5) and print() are valid; read_sensor() call is correct.
  3. Final Answer:

    Missing indentation inside the for loop -> Option C
  4. Quick Check:

    Indentation error [OK]
Quick Trick: Indent all code inside loops consistently [OK]
Common Mistakes:
MISTAKES
  • Ignoring indentation errors
  • Thinking range() is invalid
  • Assuming print() is disallowed in loops

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes