Now You Code 5: The TODO List

In this assignment we write a simple TODO list program in Python. The user interface for out TODO list app will be a basic text parser. So for example if you want to add an item to your TODO list called clean my room, you would type: add todo clean my room.

Here's a summary of the commands understood by our parser:

  • add todo-item add an item to the TODO list.
  • del todo-item removes an item from the TODO list.
  • show shows items on the TODO list
  • quit exits the program loop.

One again, we will apply problem simplification and work on this problem in 3 parts.

  1. In Part 1 we will create the command parser loop first.
  2. In Part 2 we code the add, del and show commands.

Part 1: Step 1: Problem Analysis

Implement the provided algorithm as code.

Inputs: a command string

Outputs: print the command (if valid), or print "invalid command" or quit program

Algorithm (Steps in Program):

loop
    input command
    extract first word from command
    if word equals "quit" exit loop
    if word equals "add"
       extract item from command
       print "code to add item to todo list goes here"
    else if word equals "del"
       extract item from command
       print "code to remove item from todo list goes here"
    else if word equals "show"
       print "code to show items on todo list goes here"
    else if word equals "save"
       print "code to save todo list to file goes here"
    else
      print "invalid command"

In [9]:
# Part 1: Step 2 Write code here

Part 2: Step 1: problem analysis

Next we will introduce the add, del and show functionality to the program. No longer will these commands print what they should do, they will actually get it done!

Here's what you need to change in your program:

  1. Copy and paste your code from Part 1: Step 2 above into Part 2: Step 2 below.
  2. At the very beginning before entering the program loop create an empty list in a variable called todo
  3. Code the "add" command to add the item to the todo list, and print a message saying the item was added.
  4. Code the "show" command to print each item the todo list using a for loop
  5. Code the "del" command to remove item from the list, and print a message saying item was deleted.

Here's an example of the working code:

Enter command:  add go shopping
 go shopping added.
Enter command:  add chop wood
 chop wood added.
Enter command:  add eat pizza
 eat pizza added.
Enter command:  show
TODO list:
 go shopping
 chop wood
 eat pizza
Enter command:  del chop wood
 chop wood deleted.
Enter command:  show
TODO list:
 go shopping
 eat pizza
Enter command:  quit

In [11]:
# Part 2: Step 2 Write code here

Step 3: Questions

  1. What happens when you del a TODO item which is not on the list? Explain specifically how we handle this error?

Answer:

  1. Describe a strategy you can employ to save the list to a file and load it back. How would that work?

Answer:

Step 4: Reflection

Reflect upon your experience completing this assignment. This should be a personal narrative, in your own voice, and cite specifics relevant to the activity as to help the grader understand how you arrived at the code you submitted. Things to consider touching upon: Elaborate on the process itself. Did your original problem analysis work as designed? How many iterations did you go through before you arrived at the solution? Where did you struggle along the way and how did you overcome it? What did you learn from completing the assignment? What do you need to work on to get better? What was most valuable and least valuable about this exercise? Do you have any suggestions for improvements?

To make a good reflection, you should journal your thoughts, questions and comments while you complete the exercise.

Keep your response to between 100 and 250 words.

--== Write Your Reflection Below Here ==--


In [ ]:
# RUN THIS CODE CELL TO TURN IN YOUR WORK!
from ist256.submission import Submission
Submission().submit()