0
0
Raspberry Piprogramming~10 mins

Data rotation and cleanup 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 list all files in the directory.

Raspberry Pi
import os
files = os.[1]('.')
print(files)
Drag options to blanks, or click blank then click option'
Alistdir
Brename
Cmkdir
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.remove instead of os.listdir
Trying to create a directory instead of listing files
2fill in blank
medium

Complete the code to delete a file named 'old.log'.

Raspberry Pi
import os
os.[1]('old.log')
Drag options to blanks, or click blank then click option'
Alistdir
Bremove
Cmkdir
Drename
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.listdir instead of os.remove
Trying to rename instead of delete
3fill in blank
hard

Fix the error in the code to rename 'temp.log' to 'backup.log'.

Raspberry Pi
import os
os.[1]('temp.log', 'backup.log')
Drag options to blanks, or click blank then click option'
Alistdir
Bremove
Cmkdir
Drename
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.remove instead of os.rename
Trying to list files instead of renaming
4fill in blank
hard

Fill both blanks to create a dictionary with file names as keys and their sizes as values for files larger than 1000 bytes.

Raspberry Pi
import os
files = os.listdir('.')
sizes = {file: os.path.[1](file) for file in files if os.path.[2](file) and os.path.[1](file) > 1000}
Drag options to blanks, or click blank then click option'
Agetsize
Bexists
Disfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using os.path.exists instead of os.path.isfile
Not checking if the path is a file
5fill in blank
hard

Fill all three blanks to filter files with '.log' extension, get their sizes, and keep only those larger than 5000 bytes.

Raspberry Pi
import os
files = os.listdir('.')
log_files = {file: os.path.[1](file) for file in files if file.endswith('[2]') and os.path.[3](file) > 5000}
Drag options to blanks, or click blank then click option'
Agetsize
B.log
Disfile
Attempts:
3 left
💡 Hint
Common Mistakes
Not filtering by extension
Using wrong functions for size check