add the two class functions (add_snack and list_snacks). Below I included not only the instructions, but also an Example that when you run it, it should look exactely like my example. Remember RUN YOUR CODE. Don’t stop until it works
If you look further, I put an example with a “FRUIT STORE” look at it for help
def add_snack(self): # 1. Use input 4 to ask for the information about the snack #2 Is to create a snack using the information you asked for #3 add it to the dictionary pass def list_all_snacks(self): # do not do this -----< print(self.snack_dict) # use a for loop to go one buy one and print everything from the dictionary #look at the fruit as an example, but use one of the dictionary methods (such as dict_name.values) # grab all the names of the dictionary pass #You may need to test your code. vending_machine.add_snack() <--- is how you would test it
WHAT IT SHOULD LOOK LIKE WHEN YOU RUN IT
Please select one of the following
1. Add Snack
2. list all snacks
3. find snack
4. list salty snacks
5. list sweet snacks
Enter your selection (Enter “exit” to quit): 1
ADD SNACK
What is the Snack’s Name? Chips
What is the Snack’s Type/Flavor? Salty
What is the Snack’s Size? Large
Is the Snack Healthy? No
Please select one of the following
1. Add Snack
2. list all snacks
3. find snack
4. list salty snacks
5. list sweet snacks
Enter your selection (Enter “exit” to quit): 1
ADD SNACK
What is the Snack’s Name? Chocolate
What is the Snack’s Type/Flavor? Sweet
What is the Snack’s Size? Small
Is the Snack Healthy? No
Please select one of the following
1. Add Snack
2. list all snacks
3. find snack
4. list salty snacks
5. list sweet snacks
Enter your selection (Enter “exit” to quit): 2
List Snacks
Chips – Salty – Large
Chocolate – Sweet – Small
Example you can borrow for our snack system
# Part 1 Finish the Fruit class # just self. __________________ # name and color is Strings # is_it_sweet is True or False # barcord_numberis number class Fruit: def __init__(self,name,color,is_it_sweet,barcode_number): self.name = name self.color = color self.is_it_sweet = is_it_sweet self.barcode_number = barcode_number class Fruit_store: # Part 2 I need you to create 2 empty dictionaries # fruit_by_name {name:fruit} # fruit_by_barcode {barcode:fruit} def __init__ (self): self.fruit_by_name = {} self.fruit_by_barcode = {} # part 3 # i want you to write the code that lets someone add a fruit to the store def add_fruit(self): name = input("What is the fruit's name?") color = input("what is the fruit's color?") is_it_sweet = input("is the fruit sweet?") barcode_number = input("what is the barcode number of your fruit?") fruit = Fruit(name,color,is_it_sweet,barcode_number) self.fruit_by_name[name] = fruit self.fruit_by_barcode[barcode_number] = fruit print("You have added your fruit") # part 4 # pick a dictionary, and use it to list all the fruit and its information def list_fruit(self): for f in self.fruit_by_name.values(): print(f"the fruit's name is{f.name}and the fruit's {f.color} {f.is_it_sweet} {f.barcode_number}") # part 5 # same as list_fruit, but you must check if the fruit is sweet before printing def find_all_sweet_fruit(self): for f in self.fruit_by_name.values(): if f.is_it_sweet.lower() == "true": print(f"the fruit's name is {f.name} and the fruit's {f.color} {f.is_it_sweet} {f.barcode_number}") #part 6 # the user will ask for a fruit with input, and you need to print the info def find_fruit_by_name(self): question_of_fruit = input("what fruit are you looking for?") if question_of_fruit in self.fruit_by_name.keys(): found_fruit = self.fruit_by_name[question_of_fruit] print(f"the fruit's name is {found_fruit.name} and the fruit's {found_fruit.color} {found_fruit.is_it_sweet} {found_fruit.barcode_number}") else: print("We don't have your fruit") def application_loop(self): menu = """ 1. Add A Fruit 2. List all fruits 3. find all sweet fruits 4. find fruits by name 5. End Application Enter Your selection here:""" while True: response = input(menu) if response=="1": self.add_fruit() elif response=="2": self.list_fruit() elif response == "4": self.find_fruit_by_name() elif response == "3": self.find_all_sweet_fruit() elif response == "5": break else: print("Bad answer") ranch_nine_nine= Fruit_store() #ranch_nine_nine.add_fruit() #<--- we do the code to add the fruit ranch_nine_nine.application_loop()