Exercise 2 solution import os, tempfile path = os.path.join(tempfile.gettempdir(), "all_bytes.bin") with open(path, "wb") as f: f.write(bytes(range(256))) with open(path, "rb") as f: data = f.read() print(len(data)) # 256 print(sum(1 for b in data if b >= 128)) # 128 print(data[:4]) # b'\x00\x01\x02\x03' with open(path, "rb") as f: f.seek(-5, os.SEEK_END) print(f.read().hex(" ")) # fb fc fd fe ff os.remove(path) (Run as written; the output matched the comments.) Explanation: bytes(range(256)) holds every possible byte value once, so exactly half of them (128 to 255) are 128 or more. Opening with "rb" returns bytes with no newline or encoding translation. seek(-5, os.SEEK_END) moves to five bytes before the end of the file; a negative offset is only allowed relative to the end (or the current position) in binary mode.