0
0
Operating Systemsknowledge~10 mins

File attributes and operations in Operating Systems - Interactive Code Practice

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

Complete the code to check if a file is readable.

Operating Systems
if os.access('example.txt', [1]):
    print('File is readable')
Drag options to blanks, or click blank then click option'
Aos.W_OK
Bos.R_OK
Cos.X_OK
Dos.F_OK
Attempts:
3 left
💡 Hint
Common Mistakes
Using write or execute flags instead of read flag.
2fill in blank
medium

Complete the code to open a file for writing only if it exists.

Operating Systems
with open('data.txt', '[1]') as file:
    file.write('Hello')
Drag options to blanks, or click blank then click option'
Aw
Bx
Cr+
Da
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'w' which creates the file if it doesn't exist.
3fill in blank
hard

Fix the error in the code to get the size of a file in bytes.

Operating Systems
size = os.path.[1]('file.txt')
print(size)
Drag options to blanks, or click blank then click option'
Aget_size
Bfilesize
Csizeof
Dgetsize
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect function names like get_size or filesize.
4fill in blank
hard

Fill both blanks to create a dictionary of file names and their sizes for files larger than 1000 bytes.

Operating Systems
file_sizes = {f: os.path.[1](f) for f in files if os.path.[2](f) and os.path.getsize(f) > 1000}
Drag options to blanks, or click blank then click option'
Agetsize
Bexists
Disfile
Attempts:
3 left
💡 Hint
Common Mistakes
Using exists instead of isfile for file check.
5fill in blank
hard

Fill all three blanks to filter files by extension and size, then create a dictionary with uppercase file names and their sizes.

Operating Systems
filtered = {f.[1](): os.path.[2](f) for f in files if f.[3]('.txt') and os.path.getsize(f) > 500}
Drag options to blanks, or click blank then click option'
Aupper
Bgetsize
Cendswith
Dlower
Attempts:
3 left
💡 Hint
Common Mistakes
Using lower() instead of upper(), or wrong method for extension check.