The Treasure Hunt: The Secret Files
In the bustling city of Chennai, young coder Alex discovered an ancient laptop in the attic of their new home. The laptop, covered in dust and cobwebs, intrigued Alex. It held secrets from a bygone era, waiting to be unlocked.
Determined to unravel the mystery, Alex powered on the laptop. To their surprise, it booted up with a retro operating system that presented a list of files in an archaic directory. One file caught Alexβs attention: secrets.txt
.
Opening the File
Eagerly, Alex opened the file using their Python skills:
file = open('secrets.txt', 'r')
Reading from the File
Inside, they found lines of cryptic messages and coordinates that promised to lead to a hidden treasure:
with open('secrets.txt', 'r') as file: content = file.readlines() for line in content: print(line.strip())
Writing to a File
Excited by the discovery, Alex decided to keep notes on the clues they deciphered. They created a new file, notes.txt
, to jot down their findings:
with open('notes.txt', 'w') as file: file.write('Clue 1: Follow the stars.\n') file.write('Clue 2: Seek the golden path.\n')
Appending to the File
As Alex decoded more clues, they added them to their notes:
with open('notes.txt', 'a') as file: file.write('Clue 3: Trust the wise owl.\n')
Checking File Existence
One clue suggested checking for a specific file that might have more information. Alex verified its existence before proceeding:
import os if os.path.exists('coordinates.txt'): print('Coordinates found!') else: print('Coordinates file is missing.')
Working with Binary Files
The final clue hinted at a binary file, map.bin
, containing the treasure map. Alex knew this required a different approach:
with open('map.bin', 'rb') as file: map_data = file.read() print(map_data)
Deleting a File
After successfully extracting the map, Alex realized that the secrets.txt
file could fall into the wrong hands. To protect the treasure, they deleted it:
import os if os.path.exists('secrets.txt'): os.remove('secrets.txt') print('Secrets erased.')
The Treasure
Following the mapβs instructions, Alex ventured into the heart of Chennai, navigating through bustling streets and hidden alleys. Finally, they arrived at an abandoned warehouse. Inside, they found a chest filled with vintage tech gadgets and historical artifacts, the treasure of Chennai.