Challenge - 5 Problems
CSV Logging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
Logging sensor data to CSV: Output check
You run this command on your Raspberry Pi to append temperature data to a CSV file:
What will be the last line added to
echo "$(date +%Y-%m-%d),$(date +%H:%M:%S),25.3" >> /home/pi/sensor_log.csvWhat will be the last line added to
sensor_log.csv?Raspberry Pi
echo "$(date +%Y-%m-%d),$(date +%H:%M:%S),25.3" >> /home/pi/sensor_log.csvAttempts:
2 left
💡 Hint
Think about what the echo command with date substitutions outputs.
✗ Incorrect
The echo command outputs the current date, time, and temperature separated by commas, then appends it to the CSV file.
❓ Configuration
intermediate2:00remaining
CSV logging script: Correct Python code
Which Python code snippet correctly appends a row with timestamp and sensor value to a CSV file on Raspberry Pi?
Attempts:
2 left
💡 Hint
Appending means opening the file with 'a' mode and using csv.writer properly.
✗ Incorrect
Option A opens the file in append mode with newline='' to avoid blank lines and writes a list row with timestamp and value.
❓ Troubleshoot
advanced2:00remaining
CSV file has extra blank lines after logging
You wrote a Python script on Raspberry Pi to log data to CSV. After running it multiple times, the CSV file has extra blank lines between data rows. What is the most likely cause?
Attempts:
2 left
💡 Hint
Think about how Python handles newlines on different platforms when writing CSV.
✗ Incorrect
Without newline='' in open(), Python adds extra newlines on Windows and Raspberry Pi, causing blank lines in CSV.
🔀 Workflow
advanced2:00remaining
Automating CSV logging with cron on Raspberry Pi
You want to log temperature data every 10 minutes to a CSV file automatically. Which cron job entry correctly runs a script located at /home/pi/log_temp.py every 10 minutes?
Attempts:
2 left
💡 Hint
Cron syntax for every 10 minutes uses */10 in the minutes field and full path to python.
✗ Incorrect
Option A runs the script every 10 minutes, uses full python path, and redirects output to a log file.
✅ Best Practice
expert2:30remaining
Ensuring safe concurrent writes to CSV on Raspberry Pi
Multiple processes on your Raspberry Pi write sensor data to the same CSV file simultaneously. What is the best way to avoid data corruption?
Attempts:
2 left
💡 Hint
Think about how to prevent two processes writing at the same time.
✗ Incorrect
File locking ensures only one process writes at a time, preventing corruption.