Projects · 18 / 19 Exercise Hard

To-do list with JSON

Objective

A to-do list that persists in a JSON file: at the start it loads the file if it exists and at the end it saves it.

Instructions

  • The file tareas.json contains a list of objects with the keys id, title and done (boolean). If it does not exist, start with an empty list.
  • The first line has the number n of commands: add title (the title is the rest of the line; the id is the highest existing plus 1; show OK id), done id, remove id (show OK or Error: task not found) and list (one line id [x] title per task, or No tasks if there are none).
  • When finished save the list to tareas.json with indent=2 and ensure_ascii=False.
Input
4
add comprar pan
add llamar
done 1
list
Output
OK 1
OK 2
OK
1 [x] comprar pan
2 [ ] llamar

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise