Bird
0
0

Find the bug in this Raspberry Pi Python code snippet for logging data:

medium📝 Debug Q7 of 15
Raspberry Pi - Data Logging and Databases
Find the bug in this Raspberry Pi Python code snippet for logging data:
with open('data.log', 'a') as f:
    f.write(Temperature: 30C\n)
ANo bug, code is correct
BFile mode should be 'w' not 'a'
CIncorrect file extension, should be '.txt'
DMissing quotes around string in write()
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax of write argument

    Text to write must be a string enclosed in quotes.
  2. Step 2: Identify missing quotes error

    Code lacks quotes around Temperature: 30C\n causing syntax error.
  3. Final Answer:

    Missing quotes around string in write() -> Option D
  4. Quick Check:

    Strings need quotes in write() [OK]
Quick Trick: Always quote strings in write() [OK]
Common Mistakes:
MISTAKES
  • Ignoring string syntax rules
  • Changing file mode unnecessarily
  • Thinking file extension affects syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes