file = input("File name: ").strip().lower()
extension_image = (".gif",".jpg", ".jpeg",".png")
extension_application = (".pdf","zip")
extension_text = ("txt")
condition_image = file.endswith(extension_image)
condition_application = file.endswith(extension_application)
condition_text = file.endswith(extension_text)
if condition_image == True:
normal = file.split(".")
print("image/" + str(normal[-1]))
elif condition_application == True:
normal = file.split(".")
print("application/" + str(normal[-1]))
elif condition_text == True:
normal = file.split(".")
print("text/" + str(normal[-1]))
else:
print("application/octet-stream")
File take as an input the name and the extension and i should replace the extension like (.pdf) with the type of fyle slash the extension.
New contributor
Francesco Martini is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.