7.1 Reading a personal letter
try:
with open("letter.txt", "r") as file:
content = file.read()
print(content)
except FileNotFoundError:
print("Oops, the letter can't be found.")
7.2 Adding your name to the list
name = input("What's your name? ").strip()
with open("attendance.txt", "a") as file:
file.write(f"{name}\n")
print(f"Welcome, {name}! You've been added to the list.")
7.3 Note to self
import random
import time
with open("note_to_self.txt", "w") as file:
file.write("Curiosity rarely kills a cat.\n")
file.write("Just keep purring.\n")
file.write("...