Challenge - 5 Problems
Time-lapse Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:30remaining
Output of Raspberry Pi camera capture loop
Consider this Python code snippet for a Raspberry Pi camera time-lapse. What will be printed after running this code for 3 iterations?
Raspberry Pi
import time for i in range(3): print(f"Capturing image {i+1}") time.sleep(2) print("Time-lapse complete")
Attempts:
2 left
💡 Hint
Remember that range(3) produces 0, 1, 2 but the print uses i+1.
✗ Incorrect
The loop runs 3 times with i values 0,1,2. The print statement adds 1 to i, so it prints 1,2,3. After the loop, it prints 'Time-lapse complete'.
🧠 Conceptual
intermediate1:00remaining
Understanding delay in time-lapse photography
Why is it important to include a delay (like time.sleep) between captures in a time-lapse script on Raspberry Pi?
Attempts:
2 left
💡 Hint
Think about what happens if images are taken too quickly.
✗ Incorrect
The delay controls how often images are taken, which affects the speed and smoothness of the final time-lapse video.
🔧 Debug
advanced2:00remaining
Identify the error in this time-lapse capture code
What error will this Raspberry Pi Python code produce when run?
Raspberry Pi
from picamera import PiCamera import time camera = PiCamera() for i in range(5): camera.capture('image{i}.jpg') time.sleep(1)
Attempts:
2 left
💡 Hint
Look carefully at how the filename string is constructed inside capture().
✗ Incorrect
The filename 'image{i}.jpg' is a normal string, not an f-string, so it will literally try to save as 'image{i}.jpg' instead of substituting i. This is a logical error but not a syntax error.
❓ Predict Output
advanced1:30remaining
Output of nested loops in time-lapse script
What will be the output of this code snippet?
Raspberry Pi
for hour in range(2): for minute in range(0, 60, 30): print(f"Capturing at {hour:02d}:{minute:02d}")
Attempts:
2 left
💡 Hint
Check the ranges carefully and how many times the inner loop runs.
✗ Incorrect
The outer loop runs for hour=0 and hour=1. The inner loop runs for minute=0 and 30 each time. So total 4 prints with times 00:00, 00:30, 01:00, 01:30.
📝 Syntax
expert1:30remaining
Identify the syntax error in this Raspberry Pi time-lapse script
Which option correctly identifies the syntax error in this code snippet?
Raspberry Pi
import time from picamera import PiCamera camera = PiCamera() for i in range(3) camera.capture(f'image_{i}.jpg') time.sleep(2)
Attempts:
2 left
💡 Hint
Look at the for loop syntax carefully.
✗ Incorrect
The for loop line is missing a colon at the end, which is required in Python syntax.
