SOLUTION
Before going to the code i have some tips for you.
Here is the code:
class Shopping:
#here the final_list parameter is not needed
def __init__(self):
self.final_list = []
def add_item(self, item):
self.final_list.append(item)
print("The added item is "+str(item)+" .")
def delete_item(self, item):
#I have changed this function
if item not in self.final_list:
print("The item to be removed does not exist.")
else:
self.final_list.remove(item)
print("The removed element is "+str(item)+" .")
def print_list(self):
print("The current list is $ "+str(self.final_list) + " .")
def display_menu(shopping):
print("Welcome to the shopping list \n")
print("press 1 to see the current list")
print("press 2 to add an item to current list")
print("press 3 to delete the current list")
print("press 4 to exit the program")
choice = input("Enter your choice : ")
if choice == "1":
print()
shopping.print_list()
print()
display_menu(shopping)
elif choice == "2":
print()
item = input("Please add your item : ")
print()
shopping.add_item(item)
print()
display_menu(shopping)
elif choice == "3":
print()
item = input("Enter the item you need to delete : ")
print()
shopping.delete_item(item)
print()
display_menu(shopping)
elif choice == "4":
#I have also changed this elif part
print("Exiting the program")
return
else:
print("Please enter a valid input.\n")
display_menu(shopping)
#Driver code to test the above class
if __name__ == "__main__":
shopping = Shopping()
display_menu(shopping)
___________________________________________________________________________________________________
Here is the output and image of the code:
comment if any doubt,.
working on a Python program, making a shopping list giving the user several options:to view the...
I'm making a To-Do list in Python 2 and had the program running before remembering that my professor wants me to put everything in procedures. I can't seem to get it to work the way I have it now and I can't figure it out. I commented out the lines that was originally in the working program and added procedures to the top. I've attached a screenshot of the error & pasted the code below. 1 todo_list = [] 2...
Zybooks 11.12 LAB*: Program: Online shopping cart (continued) Python 3 is the code needed and this is in Zybooks Existing Code # Type code for classes here class ItemToPurchase: def __init__(self, item_name="none", item_price=0, item_quantity=0): self.item_name = item_name self.item_price = item_price self.item_quantity = item_quantity # def __mul__(self): # print_item_cost = (self.item_quantity * self.item_price) # return '{} {} @ ${} = ${}' .format(self_item_name, self.item_quantity, self.item_price, print_item_cost) def print_item_cost(self): self.print_cost = (self.item_quantity * self.item_price) print(('{} {} @ ${} = ${}') .format(self.item_name, self.item_quantity, self.item_price,...
Q1 (2 pts) Shopping list Write a program that prompts a user for items on their shopping list and keeps prompting the user until they enter "Done" (make sure your program can stop even if the user enters "Done" with different cases, like "done"), then prints out the items in the list, line by line, and prints the total number of items on the shopping list. Output (after collecting items in the while loop) should look something like this: Apple...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string...
Hi, can someone offer input on how to address these 4 remain parts the zybook python questions? 4: Tests that get_num_items_in_cart() returns 6 (ShoppingCart) Your output ADD ITEM TO CART Enter the item name: Traceback (most recent call last): File "zyLabsUnitTestRunner.py", line 10, in <module> passed = test_passed(test_passed_output_file) File "/home/runner/local/submission/unit_test_student_code/zyLabsUnitTest.py", line 8, in test_passed cart.add_item(item1) File "/home/runner/local/submission/unit_test_student_code/main.py", line 30, in add_item item_name = str(input('Enter the item name:\n')) EOFError: EOF when reading a line 5: Test that get_cost_of_cart() returns 10 (ShoppingCart)...
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to run properly for the lab.. class ItemPurchase: def __init__(self, nameitem='none', item_prc=0, item_quntity=0, item_descrp = 'none'): self.nameitem = nameitem self.item_prc = item_prc self.item_quntity = item_quntity self.item_descrp = item_descrp def print_itemvaluecost(self): string = '{} {} @ ${} = ${}'.format(self.nameitem, self.item_quntity, self.item_prc(self.item_quntity * self.item_prc)) valuecost = self.item_quntity * self.item_prc return string, valuecost def print_itemdescription(self): string = '{}: {}'.format(self.nameitem, self.item_descrp) print(string , end='\n') return string class Shopping_Cart: #Parameter...
python programming: Can you please add comments to describe in detail what the following code does: import os,sys,time sl = [] try: f = open("shopping2.txt","r") for line in f: sl.append(line.strip()) f.close() except: pass def mainScreen(): os.system('cls') # for linux 'clear' print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print(" SHOPPING LIST ") print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%") print("\n\nYour list contains",len(sl),"items.\n") print("Please choose from the following options:\n") print("(a)dd to the list") print("(d)elete from the list") print("(v)iew the...
Q1. Write a program to simulate a grocery waiting queue. Your program should ask the user if they want to add a customer to the queue, serve the next customer in the queue, or exit. When a customer is served or added to the queue, the program should print out the name of that customer and the remaining customers in the queue. The store has two queues: one is for normal customers, another is for VIP customers. Normal customers can...
Chapter 8 Python Case study Baseball Team Manager For this case study, you’ll use the programming skills that you learn in Murach’s Python Programming to develop a program that helps a person manage a baseball team. This program stores the data for each player on the team, and it also lets the manager set a starting lineup for each game. After you read chapter 2, you can develop a simple program that calculates the batting average for a player. Then,...
Case Study Baseball Team Manager. CMSC 135 Python Chapter 7 Assignment: Use a file to save the data Update the program so it reads the player data from a file when the program starts andwrites the player data to a file anytime the data is changed What needs to be updated: Specifications Use a CSV file to store the lineup. Store the functions for writing and reading the file of players in a separate module than the rest of the...