Advertisement
kenadams53

Shopping list with suggestions

Aug 5th, 2019
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. # The user is asked to make a shopping list then some extra suggestions
  2. # are given to the user. If they like any of these extra items they are
  3. #added to the list. Python coded by Ken Adams 6 August 2019.
  4.  
  5. # This is the list of frequent items that a person may have forgot to put ontheirlist.
  6. frequent_items = ["milk", "Brown bread", "cheese", "chrisps", "sardines", "beer", "nuts","soup","jam"]
  7.  
  8. # The frequentitems are copied to a new list todays-Suggestions.
  9. #The new list will change during the program but the origional list will not change.
  10. todays_suggestions = frequent_items
  11.  
  12. #This is the users empty shopping list
  13. shopping = []
  14. # The size of the users shopping list is defined
  15. how_many = input("how many items of shopping do you have? ")
  16. how_many = int(how_many)
  17.  
  18. #A for loop is used to read in the seperate items. In order to compare the users
  19. #list with todays_suggestions all items are converted to lower case. The suggestions
  20. #are already in lower case.If an item already appears on todays-suggestions it is
  21. #removed si that todays_suggestions will only have items that the user has not listed already
  22. for item_number in range(how_many):
  23. index = item_number+1
  24. item = input("what is item number " + str(index) + "? ")
  25. item=item.lower()
  26. shopping.append(item)
  27. if item in todays_suggestions:
  28. todays_suggestions.remove(shopping[item_number])
  29.  
  30. #The user is asked if they want to see some suggestions. A for loop makes the
  31. #suggestions. As the lenght of todays_suggestions may have changed the 'len function
  32. #is used to decide how many items to loop over. Required items are added to shopping.
  33. print("We have a list of items you normally buy!")
  34. test = input("Would you like to check it and see if you forgot anything? Please type Y or N.")
  35. if test =="Y" or test == "y":
  36. for item_number in range(len(todays_suggestions)):
  37. print("We suggest " + todays_suggestions[item_number])
  38. extra = input("Would you like that? enter Y or N ")
  39. if extra == "Y" or extra == "y":
  40. shopping.append(todays_suggestions[item_number])
  41. print("OK we have added that item to your list")
  42.  
  43.  
  44. print("There are " + str(len(shopping)) + " items on my shopping list.")
  45.  
  46. #The final list is printed.
  47. print("Your final shopping list is:")
  48. print(shopping)
  49.  
  50.  
  51. print("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement