0
0
Raspberry Piprogramming~10 mins

Logging to CSV files in Raspberry Pi - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to open a CSV file for writing.

Raspberry Pi
file = open('data.csv', '[1]')
Drag options to blanks, or click blank then click option'
A'w'
B'a'
C'r'
D'x'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'r' mode instead of 'w' mode.
2fill in blank
medium

Complete the code to import the module needed to write CSV files.

Raspberry Pi
import [1]
Drag options to blanks, or click blank then click option'
Acsv
Bjson
Cos
Dsys
Attempts:
3 left
💡 Hint
Common Mistakes
Importing unrelated modules like json or os.
3fill in blank
hard

Fix the error in the code to write a row to the CSV file.

Raspberry Pi
writer = csv.writer(file)
writer.[1](['time', 'temperature'])
Drag options to blanks, or click blank then click option'
Areadrow
Bwriteline
Cwritecsv
Dwriterow
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-existent methods like 'writeline' or 'readrow'.
4fill in blank
hard

Fill both blanks to open a CSV file and write a header row.

Raspberry Pi
with open('log.csv', [1], newline=[2]) as file:
    writer = csv.writer(file)
    writer.writerow(['date', 'value'])
Drag options to blanks, or click blank then click option'
A'w'
BTrue
C''
D'r'
Attempts:
3 left
💡 Hint
Common Mistakes
Using read mode 'r' or setting newline to True.
5fill in blank
hard

Fill all three blanks to write multiple rows to a CSV file using a loop.

Raspberry Pi
with open('data.csv', [1], newline=[2]) as file:
    writer = csv.writer(file)
    for [3] in range(3):
        writer.writerow([f'Day {i+1}', i*10])
Drag options to blanks, or click blank then click option'
A'w'
B''
Ci
DTrue
Attempts:
3 left
💡 Hint
Common Mistakes
Using append mode instead of write, omitting newline='' causing blank lines, or wrong loop variable.