Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
A to-do list is kept in a JSON file as a list of texts. Write add_task(name, task), which adds a task to the list in the file (the file may not exist yet), and done(name, task), which removes a task and gives True, or gives False if the task is not there. Test with the file todo.json.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. Both functions follow the pattern: load with a default, change, save.
Check. After two adds: ['wash', 'study']. Removing wash works (True). Removing cook finds nothing (False). The file holds ['study'].
Answer: True False, and then ['study'].
Log in to join the discussion.
Loading…