Question

In: Computer Science

Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt...

Grocery List Program

  • Write a program that keeps track of the user's grocery list items.
  • Prompt the user if they'd like to (each action is a function):
  • See the list
  • Display all items (if any) in the list
  • Add item to their list
  • Confirm with the user before adding item (y/n or yes/no)
  • If they enter a duplicate item, notify them the item already exists
  • Remove items from their list
  • Confirm with the user before removing item (y/n or yes/no)
  • Search for items in their list
  • Allow user to search for items
  • Display the items found (if any) or notify user if nothing is found
  • Your program must perform error checking
  • Be sure to code this as a stand alone module
  • __name__ == "__main__"
  • Be sure to use functions to break apart and modularize your code
  • The main part of your program must be simple with mostly function calls
  • I will remove points if your main is not broken apart into modules

please make input functions. For example, you need to confirm with the user when removing or adding, both are yes/no (y/n) responses, these can call the SAME function which will take care of making sure the input is valid.

    

  

Programming language: Python

Requirement: Please tightly follow up the rules and provide multiple functions. The output needs to be exactly the same and use try except valueerror to control input.

Solutions

Expert Solution

class Item:
    see_list=["apple","banana","carrot","beetroot"]
    def __init__(self,list_of_items):
        self.list_of_items=list_of_items
    def Menu(self):
        print("--------------------------------------")
        print("Available Options for Main Menu")
        print("1. See List")
        print("2. Display Items List")
        print("3. Add items to the list")
        print("4. Remove items from the list")
        print("5. Search for item in the list")
        print("0 Exit Main Menu")
        print("--------------------------------------")
        print("Enter option to continue")
        option=int(input())
        return option
    def See_List(self):
        print("List of items Available")
        for item in self.see_list:
            print(item)
    def Display_items(self):
        print("The following are the items in the list")
        for num,item in enumerate(self.list_of_items):      #Here enumerate is used to get track of item number. num+1 will give you the serial number of item
            print(num+1,item)
    def Add_items(self):
        print("Enter item to add")
        item_to_add=input()
        if item_to_add not in self.list_of_items:
            print("Please confirm yes/no to add an item into the list")
            confirm=input()
            if confirm=="yes":
                print("Item : ",item_to_add," added to list")
                self.list_of_items.append(item_to_add)
            else:
                print("Item not added")
                pass
        else:
            print("Item already exists in the list")
    def Remove_items(self):
        print("Enter item to remove")
        item_to_remove=input()
        if item_to_remove not in self.list_of_items:
            print("Item not present in list")
        else:
            print("Please confirm yes or no to remove item")
            confirm=input()
            if confirm=="yes":
                print("Item : ",item_to_remove," removed from list")
                self.list_of_items.remove(item_to_remove)
            else:
                print("Item not removed")
                pass
    def Search_items(self):
        print("Enter item to search")
        item_to_search=input()
        if item_to_search not in self.list_of_items:
            print("Item not found in list")
        else:
            print("Item found :",item_to_search)

    
    
if __name__=="__main__":
    obj=Item([]) #Providing empty list to initialise for constructor.
    ans=True
    try:
      while(ans):
        option=obj.Menu()
        if option==1:
          obj.See_List()
        elif option==2:
          obj.Display_items()
        elif option==3:
          obj.Add_items()
        elif option==4:
          obj.Remove_items()
        elif option==5:
          obj.Search_items()
        else:
          ans=False
    except:
      print("An error occured!!! Program Stopped")
      
        
 

#Please do mind the indendation else you will get errors. I am attaching the output of the program for your reference.

  

#Please provide positive rating if you like my work.(This is just a comment. You can delete it)

   


Related Solutions

Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (%...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (% & loop) 1. Euclid’s Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm :while b ≠ 0 temp = b b = a mod t a =...
create a program that will verify a user's login credentials. The program should prompt the user...
create a program that will verify a user's login credentials. The program should prompt the user to enter his/her username and password at the keyboard. Then it should read the data from a data file named "login.txt". The file "login.txt" will contain a list of 3 valid usernames and passwords to verify the login information supplied by a user.  If the username and password entered by the user matches one of the sets read from the file, the program should print...
Write C++ a program that shows a class called gamma that keeps track of how many...
Write C++ a program that shows a class called gamma that keeps track of how many objects of itself there are. Each gamma object has its own identification called ID. The ID number is set equal to total of current gamma objects when an object is created. Test you class by using the main function below. int main()    {    gamma g1;    gamma::showtotal();    gamma g2, g3;    gamma::showtotal();    g1.showid();    g2.showid();    g3.showid();    cout <<...
Development Strategies Lucas is a proud owner of a small grocery store wherein he keeps track...
Development Strategies Lucas is a proud owner of a small grocery store wherein he keeps track of his business transactions and records on his own personal computer. Using his knowledge, he was able to create a database to keep track of the inventory which is manually updated. Using his self-devised system, he was able to track expenses and do the payroll for his employees. The business itself has grown out of proportion and Lucas decided to install a software to...
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that...
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that asks for the name of the item and the price of each item, and then displays these on the screen. Refer to the print() and input() statements covered in the module. Do NOT use loops as it will be covered in later modules. Apples 2.10 Hamburger 3.25 Milk 3.49 Sugar 1.99 Bread 1.76 Deli Turkey 7.99 Pickles 3.42 Butter 2.79
Create a program that keeps track of the following information input by the user: First Name,...
Create a program that keeps track of the following information input by the user: First Name, Last Name, Phone Number, Age Now - let's store this in a multidimensional array that will hold 10 of these contacts. So our multidimensional array will need to be 10 rows and 4 columns. You should be able to add, display and remove contacts in the array. In Java
create a program that asks user math questions and keeps track of answers... Python Allow the...
create a program that asks user math questions and keeps track of answers... Python Allow the user to decide whether or not to keep playing after each math challenge. Ensure the user’s answer to each math problem is greater than or equal to zero. Keep track of how many math problems have been asked and how many have been answered correctly. When finished, inform the user how they did by displaying the total number of math problems, the number they...
Using Python 3, Write a class called GolfScore that keeps track of the score for a...
Using Python 3, Write a class called GolfScore that keeps track of the score for a person playing a round of golf. We will limit the round to 9 holes, just to make testing easier. As a reminder, the holes on the golf course are numbered 1 – 9. Create a class level variable named NUM_OF_HOLES set to 9. Methods to be written: The constructor – sets the score for all holes to -1 addScore (hole, score) – this method...
C++ : Write a program that creates a login name for a user, given the user's...
C++ : Write a program that creates a login name for a user, given the user's first name, last name, and a four-digit integer as input. Output the login name, which is made up of the first five letters of the last name, followed by the first letter of the first name, and then the last two digits of the number (use the % operator). If the last name has less than five letters, then use all letters of the...
Write a program that converts the user's number into the desired unit of measurement. The user...
Write a program that converts the user's number into the desired unit of measurement. The user will pick the desired unit from a menu shown below. Ask the follow-up question (the number to convert) and do the math ONLY if the user picks a valid choice from the menu. You can see the conversions / multipliers needed for this program in the output section below. Menu/Prompt: Enter the number that corresponds to your desired unit conversion from the choices below:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT