Advertisement
Guest User

Milestone 1

a guest
May 18th, 2025
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. # 1. Create a greeting at the top of your script.
  2. #Greeting for users.
  3. print ("Welcome to Green Valley Grocers Shopping List App!")
  4.  
  5. # 2. Initialize an empty list for holding the shopping list items.
  6. # Empty shopping list to start for users.
  7. shopping_list = []
  8.  
  9. # 3. Create 3 variables that prompt the user for items to add to the shopping list.
  10. # 🚨⚠️ Do not "hard code" answers for these variables. Hard coding is when you answer the inputs directly into the code. The answer should come through the terminal by the person using the program or script. ⚠️🚨
  11. #Inputs in order for users to be prompted to provide feedback in a sense to add the items they want in their shopping list/cart.
  12. item1 = input("Enter item: ")
  13. item2 = input("Enter item: ")
  14. item3 = input("Enter item: ")
  15. # Open a file in write mode and save the Items
  16. # Created a save file within the coding in order to save their items they've inputted.
  17. with open("shopping_list.txt", "w") as file:
  18. file.write(f"{item1}\n")
  19. file.write(f"{item2}\n")
  20. file.write(f"{item3}\n")
  21.  
  22. # 4. Using a list method, add these items to the list you created in step 3.
  23. # Combines the items they've inputted using the "append" command.
  24. shopping_list.append(item1)
  25. shopping_list.append(item2)
  26. shopping_list.append(item3)
  27.  
  28. # 5. Display the updated shopping list using the list variable and f-string.
  29. # Displays their new and updated shopping list that they have input themselves into the coding program.
  30. print(f"\nYour updated shopping list: {shopping_list}")
  31. # 6. The program should have brief descriptive comments describing each section of code.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement