SimeonTs

SUPyF2 Text-Pr.-Ex. - 03. Extract File

Oct 27th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. """
  2. Text Processing - Exercise
  3. Check your code: https://judge.softuni.bg/Contests/Practice/Index/1740#2
  4.  
  5. SUPyF2 Text-Pr.-Ex. - 03. Extract File
  6.  
  7. Problem:
  8. Write a program that reads the path to a file and subtracts the file name and its extension.
  9.  
  10. Examples:
  11. Input:
  12. C:\Internal\training-internal\Template.pptx
  13. Output:
  14. File name: Template
  15. File extension: pptx
  16.  
  17. Input:
  18. C:\Projects\Data-Structures\LinkedList.cs
  19. Output:
  20. File name: LinkedList
  21. File extension: cs
  22. """
  23. text = input()[::-1]
  24. new_text = ""
  25.  
  26. for letter in text:
  27.     if letter == "\\":
  28.         break
  29.     new_text += letter
  30. file, extension = new_text[::-1].split(".")
  31. print(f"File name: {file}")
  32. print(f"File extension: {extension}")
Add Comment
Please, Sign In to add comment