Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Grocery Shopping program in python! only in intermeddiate python so try to keep

ID: 671965 • Letter: G

Question

 Grocery Shopping program in python! only in intermeddiate python so try to keep the code simple as possible! Not in honors   class name: itemType --------------------------  data attributes:   name   price  class methods:    __init__            allow the user to create items two ways               item1 = itemType()             this should create an item with the name "no name"             and the price 0.0               item2 = itemType( "doll", 5.29 )             this should create an item named "doll" wiht the price 5.29    __str__            this should return a string            price with dollar sign, then item name            for item2, you should return this string "$5.29 doll"    setName   getName   setPrice   getPrice          mutator methods should change the appropriate data attribute,          accessor methods should return the appropriate data atribute  HONORS STUDENTS You must make name and price private attributes. Don't let the programmer access them directly, only through accessor and mutator methods. Modify init and the mutator methods so that they make sure the name is a string and the price is a number (int or float). Do not allow negative prices. If a bad value is passed in, print an error  message, and do not change the data attribute.   class name: shoppingBasketType ---------------------------------------  data attributes:    contents  - all the items in the basket, can be a list, can be something else, up to you     If you want the basket class to have some other data attributes, you may create more.  class methods:    __init__         create an empty shopping basket    __str__       create and return a multi-line string,       first line is "shopping basket", next lines are        all the items in the shopping basket, one item per line,        put a number in front of each item,        for example, if the basket contained only one item, a doll,        you should make this string              shopping basket              1) $5.29 doll        if the basket if empty, the string should be this              shopping basket              no items         REGULAR STUDENTS        If your basket contains multiples of the same kind of item,        you can print them all individually. For example, if your basket        contains a doll, a truck, and another doll, you can print this              shopping basket              1) $5.29 doll              2) $7.99 truck              3) $5.29 doll         HONORS STUDENTS        Your shopping basket must keep track of how many of each kind        of item is in the basket. If you put a doll, a truck, and another doll,        into you basket, you must print this (note the quantity number after doll)                shopping basket                1) $5.29 doll (2)                2) $7.99 truck    addItem        This method must take a parameter of type itemType        and add it to the contents     removeItem        This method must take an item number        and remove the corresponding item from the contents,        note that the number should be what the user sees on the screen,        that is not the same as the list index (differs by 1)         HONORS STUDENTS        If the user has a basket with a truck and two dolls,         and wants to remove a doll, ask how many to remove        (validate that the number to remove is valid)        If the user wants to remove an item that they only have one of,        just remove the item, do not ask how many to remove.    basketTotal        add up and return the total price of all items in the basket (float)   main program ------------------ Create a simple shopping program. The program should display a list of five items for sale. The names and prices of the items are up to you. That is what the store has in stock. You can assume the store has multiple copies of each item.  This store sells the following items 1) $7.99 truck 2) $5.29 doll 3) $15.99 big box of legos 4) $3.50 plush puppy 5) $3.50 plush kitten  Print the store menu. The store menu must look like this.  What do you want to do? 1)  - 5) put an item in your basket 0) view your basket  If the user selects 1, 2, 3, 4, or 5, add the appropriate item to their basket. If they select 0, print their basket, print their total (unless the basket is empty), and then display the basket menu  1)  - N) remove an item from your basket 0) continue shopping  N should be the number of items in the basket If the user chooses 0, they should see the list of items for sale and the store menu again. 

Explanation / Answer

def shoppingbasket():
        quitshop = False
        shoppinglist = []

        while (quitshop == False):
            print (" ")
            print("Your shopping basket contains ")
            print (" ")
            for item in shoppingbasket:
                print(item)
              

            print (" ")
            print ("Menu")
            print (" ")
            print ("0 = add multiple items to list")
            print ("1 = add item to list")
            print ("2 = remove item from end")
            print ("3 = remove specific item")
            print ("4 = reverse list")
            print ("5 = print out some of the list")
            print ("6 = sort into alphabetical order")
            print ("9 = quit")
            userchoice = int(input ("Please enter the option you want to proceed with "))

            if (userchoice ==0):
                print("You chose option 0")
              
                additem = ""
  
                while additem != "stop":
                    additem = input ("Please enter item for list: ")

                    if additem != "stop" and additem"":
                        shoppinglist.append(additem)
                  
            elif (userchoice ==1):
              
                print("You chose option 1")
                additem = input ("Please enter an item you want to add: ")
                shoppinglist.append(additem)
            elif (userchoice ==2):
                print("You chose option 2")
                print("The program will remove the last item from the list")
                shoppinglist.pop()
            elif (userchoice ==3):
                print("You chose option 3")
                positiontode1 = int(input("Which item would you like to delete? (enter a number)"))
                del(shoppinglist[positiontode1])
            elif (userchoice ==4):
                print("You chose option 4")
                print("This will reverse your list")
                shoppinglist.reverse()
            elif (userchoice ==5):
                print("You chose option 5")
                end = int(input("Which item should we end at? (Insert a number)"))
                for printlist in range(end):
                    print (shoppinglist[printlist])
            elif (userchoice ==6):
                print("You chose option 6")
                shoppinglist.sort()
            elif (userchoice ==9):
                print("You have chosen to quit the program")
                quit
                quitshop = True
               
            else:
                print ("error")
                print ("Try again")

if __name__== "__main__":
    shoppingbasket()