-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextensions.py
More file actions
25 lines (21 loc) · 867 Bytes
/
extensions.py
File metadata and controls
25 lines (21 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# In a file called extensions.py, implement a program that prompts the user for the name of a file and then outputs
# that file’s media type if the file’s name ends, case-insensitively, in any of these suffixes:
# If the file’s name ends with some other suffix or has no suffix at all, output application/octet-stream instead, which is a common default.
suffixes = {".gif": "image/gif",
".jpg": "image/jpeg",
".jpeg": "image/jpeg",
".png": "image/png",
".pdf": "application/pdf",
".txt": "text/plain",
".zip": "application/zip"
}
file = str(input("File name: ")).lower().strip().strip(".")
bingo = str()
for suffix in suffixes:
if suffix in file:
bingo = suffixes.get(suffix)
break
if bingo:
print(bingo)
else:
print("application/octet-stream")