superbgate_9999

Untitled

Apr 14th, 2024
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #Read Square Eared Story
  2. file = open("henryTheSquareEaredCat.txt", 'r')
  3. #for line in file:
  4. #print(line, end="")
  5.  
  6. #file.close()
  7. #Write Pentagon Eared Story
  8. file = open("henryTheSquareEaredCat.txt", 'r')
  9.  
  10. newLines = ['Pentagon', 'pentagon']
  11. for line in file:
  12. if ['Square', 'square'] in line:
  13. newLine = line.replace(['Square', 'Pentagon'], ['square', 'pentagon'])
  14. newLines.append(newLine)
  15. else:
  16. newLines.append(line)
  17. file.close()
  18.  
  19. print(newLines)
  20.  
  21. with open("henryThePentagonEaredCat.txt", 'w') as newFile:
  22. for newLine in newLines:
  23. newFile.write(newLine)
  24. newFile.close()
  25.  
  26. #Verify new file exists
  27. import os
  28. if os.path.exists("henryThePentagonEaredCat.txt"):
  29. print("Nailed It!")
  30. else:
  31. print("Did NOT nail it")
Add Comment
Please, Sign In to add comment