Skip to content

Commit

Permalink
Create 15.6.7 Reverse a File
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeHS-Solutions authored Mar 15, 2024
1 parent 8eb0155 commit 13223fa
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
file = open("story.txt", "r")
content = file.read()
file_length = len(content)
reverse = ""
file.seek(0,2)
position = file.tell()

for i in range((file_length) + 1):
file.seek(position - i)
reverse += file.read(1)
file.close()

reversed_file = open("reversed.txt", "w")
reversed_file.write(reverse)
reversed_file.close()

0 comments on commit 13223fa

Please sign in to comment.