Bird
0
0

Identify the error in this code snippet:

medium📝 Debug Q14 of 15
Raspberry Pi - Camera Module
Identify the error in this code snippet:
from picamera2 import Picamera2
picam2 = Picamera2()
picam2.capture_file('image.jpg')
picam2.stop()
ANo error; code runs fine
BWrong method name; should be capture_image()
CFile extension must be .png, not .jpg
DMissing call to picam2.start() before capture_file
Step-by-Step Solution
Solution:
  1. Step 1: Check method usage order

    Before capturing an image, the camera must be started with start(). This code skips that step.
  2. Step 2: Verify method names and file formats

    capture_file() is correct method name, and .jpg is a valid extension. So no error there.
  3. Final Answer:

    Missing call to picam2.start() before capture_file -> Option D
  4. Quick Check:

    start() needed before capture_file() [OK]
Quick Trick: Always start camera before capturing [OK]
Common Mistakes:
MISTAKES
  • Skipping picam2.start() before capture
  • Assuming capture_file() is incorrect method
  • Thinking file extension causes error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Raspberry Pi Quizzes