Bird
0
0

Identify the error in this code snippet that reads from channel 1:

medium📝 Debug Q14 of 15
Raspberry Pi - SPI Communication
Identify the error in this code snippet that reads from channel 1:
def read_sensor():
    value = read_adc[1]
    return value

print(read_sensor())
AIncorrect print syntax
BUsing square brackets instead of parentheses to call read_adc
CMissing return statement in function
DFunction name is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Check function call syntax inside read_sensor

    The code uses read_adc[1], which is invalid syntax for calling a function.
  2. Step 2: Correct syntax for function call

    It should be read_adc(1) with parentheses to call the function.
  3. Final Answer:

    Using square brackets instead of parentheses to call read_adc -> Option B
  4. Quick Check:

    Function calls need parentheses = Using square brackets instead of parentheses to call read_adc [OK]
Quick Trick: Use parentheses, not brackets, to call functions [OK]
Common Mistakes:
MISTAKES
  • Using brackets [] instead of parentheses ()
  • Forgetting to return value
  • Misusing print statement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes