Now You Code 2: Shopping List

Write a program to input a list of grocery items for your shopping list and then writes them to a file a line at a time. The program should keep asking you to enter grocery items until you type 'done'.

After you complete the list, the program should then load the file and read the list back to you by printing each item out.

Sample Run:

Let's make a shopping list. Type 'done' when you're finished:
Enter Item: milk
Enter Item: cheese
Enter Item: eggs
Enter Item: beer
Enter Item: apples
Enter Item: done
Your shopping list:
milk
cheese
eggs
beer
apples

Step 1: Problem Analysis

Inputs:

Outputs:

Algorithm (Steps in Program):


In [ ]:
filename = "NYC2-shopping-list.txt"
## Step 2: write code here

Step 3: Refactoring

Refactor the part of your program which reads the shopping list from the file into a separate user-defined function called readShoppingList re-write your program to use this function.

ReadShoppingList function

Inputs:

Outputs:

Algorithm (Steps in Program):


In [2]:
## Step 4: Write program again with refactored code.
def readShoppingList():
    shoppingList = []
    # todo read shopping list here
    
    return shoppingList


# TODO Main code here

Step 5: Questions

  1. Is the refactored code in step 4 easier to read? Why or why not?

Answer:

  1. Explain how this program could be refactored further (there's one thing that's obvious).

Answer:

  1. Describe how this program can be modified to support multiple shopping lists?

Answer:

Step 6: 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 ==--