Write a Python program that accepts a filename from the user and prints the extension of the file.
Write a Python program that accepts a filename from the user and prints the extension of the file.
Program
def myfun():
file = input("Input the Filename: ")
f_ext = file.split(".")
print("The extension of the file is : " + repr(f_ext[-1]))
if __name__=="__main__":
myfun()
Output:
Input the Filename: sateeshm.java
The extension of the file is : 'java'
Input the Filename: sateeshm.jsp
The extension of the file is : 'jsp'