Use your modules and file-handling knowledge to write inventory data to a file and read it back. Simulate a simple store stock tracker.
YOUR TASK
Create a program that:
Writes at least 3 items (name + quantity) to a file called inventory.txt
Reads the file back and prints each line
Uses with open(...) for both operations
Prints a "Total items:" count at the end
Need a hint?
Write the file: with open("inventory.txt", "w") as f: f.write("Apples: 50\n")
Read it back: with open("inventory.txt", "r") as f: lines = f.readlines() for line in lines: print(line.strip()) print(f"Total items: {len(lines)}")
Expected output:
Apples: 50
Bananas: 30
Oranges: 20
Total items: 3
Code Editor
Ready
Output
Console
Console initialized...
Ready for Project 4: File-Based Inventory
> Write items to a file, then read them back
> Complete button unlocks when output matches!