0
0
Intro to Computingfundamentals~10 mins

File types and associations in Intro to Computing - Interactive Code Practice

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

Complete the code to identify the file type by its extension.

Intro to Computing
file_name = "document[1]"
if file_name.endswith('.txt'):
    print("This is a text file.")
Drag options to blanks, or click blank then click option'
A.docx
B.pdf
C.jpg
D.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing an extension that does not represent a text file.
Forgetting the dot before the extension.
2fill in blank
medium

Complete the code to open an image file based on its extension.

Intro to Computing
file_name = "photo[1]"
if file_name.endswith('.png') or file_name.endswith('.jpg'):
    print("Open image viewer")
Drag options to blanks, or click blank then click option'
A.gif
B.jpg
C.mp3
D.txt
Attempts:
3 left
💡 Hint
Common Mistakes
Selecting an audio or text file extension instead of an image.
Confusing file extensions with similar names.
3fill in blank
hard

Fix the error in the code to correctly associate a file type with its program.

Intro to Computing
file_extension = '.pdf'
if file_extension == [1]:
    print("Open with PDF reader")
Drag options to blanks, or click blank then click option'
Apdf
BPDF
C.pdf
Dpdf.
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the dot in the extension string.
Using uppercase letters inconsistently.
4fill in blank
hard

Fill both blanks to create a dictionary mapping file extensions to their associated programs.

Intro to Computing
file_associations = { [1]: "Text Editor", [2]: "Image Viewer" }
Drag options to blanks, or click blank then click option'
A".txt"
B".mp3"
C".jpg"
D".exe"
Attempts:
3 left
💡 Hint
Common Mistakes
Using extensions that do not match the program type.
Forgetting to include quotes around the extensions.
5fill in blank
hard

Fill all three blanks to filter file names by extension and create a list of those files.

Intro to Computing
files = ["doc1.txt", "image.png", "song.mp3", "notes.txt"]
txt_files = [f for f in files if f.endswith([1]) or f.endswith([2])]
print(txt_files)  # Should print files ending with [3]
Drag options to blanks, or click blank then click option'
A".txt"
B".mp3"
D".png"
Attempts:
3 left
💡 Hint
Common Mistakes
Using different extensions that do not match the comment.
Mixing image or audio extensions instead of text.