0
0
Intro to Computingfundamentals~10 mins

Why file organization matters in Intro to Computing - Test Your Understanding

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

Complete the code to create a folder named 'Documents' to keep files organized.

Intro to Computing
import os
os.[1]('Documents')
Drag options to blanks, or click blank then click option'
Amkdir
Brename
Cremove
Dlistdir
Attempts:
3 left
💡 Hint
Common Mistakes
Using remove instead of mkdir deletes folders.
Using listdir lists files but does not create folders.
2fill in blank
medium

Complete the code to list all files in the 'Documents' folder.

Intro to Computing
import os
files = os.[1]('Documents')
print(files)
Drag options to blanks, or click blank then click option'
Amkdir
Bremove
Clistdir
Drename
Attempts:
3 left
💡 Hint
Common Mistakes
Using mkdir creates a folder instead of listing files.
Using remove deletes files or folders.
3fill in blank
hard

Fix the error in the code to move a file named 'notes.txt' into the 'Documents' folder.

Intro to Computing
import os
os.[1]('notes.txt', 'Documents/notes.txt')
Drag options to blanks, or click blank then click option'
Acopy
Brename
Cmove
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using move causes an error because it's not in os module.
Using delete removes the file instead of moving it.
4fill in blank
hard

Fill both blanks to create a dictionary that maps file names to their sizes in the 'Documents' folder.

Intro to Computing
import os
sizes = {file: os.path.[1](os.path.join('Documents', file)) for file in os.[2]('Documents')}
Drag options to blanks, or click blank then click option'
Agetsize
Bmkdir
Clistdir
Dremove
Attempts:
3 left
💡 Hint
Common Mistakes
Using mkdir instead of listdir does not list files.
Using remove deletes files instead of getting size.
5fill in blank
hard

Fill all three blanks to filter files larger than 1000 bytes and create a dictionary with their names and sizes.

Intro to Computing
import os
large_files = {file: os.path.[1](os.path.join('Documents', file)) for file in os.[2]('Documents') if os.path.getsize(os.path.join('Documents', file)) [3] 1000}
Drag options to blanks, or click blank then click option'
Agetsize
Blistdir
C>
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' filters smaller files instead of larger.
Using mkdir instead of listdir does not list files.