Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # The user is asked to make a shopping list then some extra suggestions
- # are given to the user. If they like any of these extra items they are
- #added to the list. Python coded by Ken Adams 6 August 2019.
- # This is the list of frequent items that a person may have forgot to put ontheirlist.
- frequent_items = ["milk", "Brown bread", "cheese", "chrisps", "sardines", "beer", "nuts","soup","jam"]
- # The frequentitems are copied to a new list todays-Suggestions.
- #The new list will change during the program but the origional list will not change.
- todays_suggestions = frequent_items
- #This is the users empty shopping list
- shopping = []
- # The size of the users shopping list is defined
- how_many = input("how many items of shopping do you have? ")
- how_many = int(how_many)
- #A for loop is used to read in the seperate items. In order to compare the users
- #list with todays_suggestions all items are converted to lower case. The suggestions
- #are already in lower case.If an item already appears on todays-suggestions it is
- #removed si that todays_suggestions will only have items that the user has not listed already
- for item_number in range(how_many):
- index = item_number+1
- item = input("what is item number " + str(index) + "? ")
- item=item.lower()
- shopping.append(item)
- if item in todays_suggestions:
- todays_suggestions.remove(shopping[item_number])
- #The user is asked if they want to see some suggestions. A for loop makes the
- #suggestions. As the lenght of todays_suggestions may have changed the 'len function
- #is used to decide how many items to loop over. Required items are added to shopping.
- print("We have a list of items you normally buy!")
- test = input("Would you like to check it and see if you forgot anything? Please type Y or N.")
- if test =="Y" or test == "y":
- for item_number in range(len(todays_suggestions)):
- print("We suggest " + todays_suggestions[item_number])
- extra = input("Would you like that? enter Y or N ")
- if extra == "Y" or extra == "y":
- shopping.append(todays_suggestions[item_number])
- print("OK we have added that item to your list")
- print("There are " + str(len(shopping)) + " items on my shopping list.")
- #The final list is printed.
- print("Your final shopping list is:")
- print(shopping)
- print("bye")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement