Build: Multiple Lines
Construct the code using `with open`. Write **two separate lines** to `report.txt` in append mode (`'a'`):
Line 1: `Status: OK\n`
Line 2: `Data logged.\n`
Challenge: Writing Numbers
The `.write()` method only accepts strings! Type code to write a score (e.g., `score = 100`) to `scores.txt` in write mode (`'w'`). Remember to convert the number to a string first using `str()`. Include a newline `\n`.
Write Using a Loop
Imagine you have a list: `items = ["CPU", "GPU", "RAM"]`. Write code using a `for` loop inside a `with open` block to write each item to `hardware.log` (append mode `'a'`), adding a newline `\n` after each item.
Advanced Mini Missions
Apply your skills to these challenges. Pay attention to filenames, modes, and required content format!
Adv. Mission 1: Single Write, Multiple Lines
Using only **one** `.write()` call, create/overwrite `greeting.txt` (mode `'w'`) with the exact content:
`Hello\nWorld\n`
Adv. Mission 2: Append Formatted Data
You have `user_id = 5` and `action = "updated"`. Append a line to `activity.log` (mode `'a'`) in the format: `ID: 5 - Action: updated\n`. Remember to convert `user_id` to a string!
Adv. Mission 3: Overwrite with Key-Value
Overwrite (`'w'`) the file `settings.ini` with the following key-value pairs, each on its own line (ending with `\n`):
`theme=dark`
`autosave=true`
Module 24 Advanced Practice Complete!
Excellent job tackling these advanced file writing exercises! You're building solid persistence skills.
Review the basic practice or watch the video lesson if needed, or head back to the course menu.