Bird
0
0

Why does this code raise an error?

medium📝 Debug Q7 of 15
Raspberry Pi - Display and Output
Why does this code raise an error?
from RPLCD.i2c import CharLCD
lcd = CharLCD('PCF8574', 0x27)
lcd.write_string(1234)
APCF8574 is not a valid i2c_expander
BIncorrect I2C address format
CMissing lcd.clear() before writing
Dwrite_string expects a string, not an integer
Step-by-Step Solution
Solution:
  1. Step 1: Check the argument type for write_string

    write_string requires a string argument, but 1234 is an integer.
  2. Step 2: Understand type error cause

    Passing an integer causes a TypeError because it cannot be converted automatically.
  3. Final Answer:

    write_string expects a string, not an integer -> Option D
  4. Quick Check:

    write_string argument must be string [OK]
Quick Trick: Always convert numbers to strings before write_string [OK]
Common Mistakes:
MISTAKES
  • Passing integers directly to write_string
  • Assuming automatic conversion happens
  • Ignoring type requirements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes