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 Constructor
def __init__(self, cust_name = 'none', currentdate = 'January 1, 2017', cartitems = []):
self.cust_name = cust_name
self.currentdate = currentdate
self.cartitems = cartitems
def additem(self, string):
print('\nADD ITEM ' , end='\n')
nameitem = str(input('please Enter item name: '))
item_descrp = str(input('\n please Enter the item descrpt: '))
item_prc = int(input('\nplease Enter the item price: '))
item_quntity = int(input('\n please Enter the item quanty: '))
self.cartitems.append(ItemPurchase(nameitem, item_prc, item_quntity, item_descrp))
def removeitem(self):
print('\nREMOVE ITEM ',end='\n')
string = str(input('please Enter name to delete: '))
i1 = 0
for item1 in self.cartitems:
if(item1.nameitem == string):
del self.cartitems[i1]
i1 += 1
flagvalue=True
break
else:
flagvalue=False
if(flagvalue==False):
print('Item could not found . Nothing removed')
def modifiedtem(self):
print('\nCHANGE QUANTITY' , end='\n')
name1 = str(input('please Enter name: '))
for item1 in self.cartitems:
if(item1.nameitem == name1):
quantity1 = int(input('please Enter quantity: '))
item1.item_quntity = quantity1
flagvalue=True
break
else:
flagvalue=False
if(flagvalue==False):
print('do not be modified')
def get_numberitems_cart(self):
numitems=0
for item1 in self.cartitems:
numitems= numitems+item1.item_quntity
return numitems
def get_valuecost_of_cart(self):
total_valuecost = 0
valuecost = 0
for item1 in self.cartitems:
valuecost = (item1.item_quntity * item1.item_prc)
total_valuecost += valuecost
return total_valuecost
def displaytotal():
total_valuecost = get_valuecost_of_cart()
if (total_valuecost == 0):
print('empty cart')
else:
result_cart()
def printdescrip(self):
print('\nOUTPUT values\' DESCRIPTIONS')
print('{}\'s cart_shopping - {}'.format(self.cust_name, self.currentdate) , end='\n')
print('\nItem desrip' , end='\n')
for item1 in self.cartitems:
print('{}: {}'.format(item1.nameitem, item1.item_descrp) , end='\n')
def result_cart(self):
new1=Shopping_Cart()
print('\nOUTPUT', end='\n')
print('{}\'s cart_shopping - {}'.format(self.cust_name, self.currentdate))
print('Numb of Items:', new1.get_numberitems_cart(), end='\n\n')
tc1 = 0
for item1 in self.cartitems:
print('{} {} @ ${} = ${}'.format(item1.nameitem, item1.item_quntity,
item1.item_prc, (item1.item_quntity * item1.item_prc)))
tc1 += (item1.item_quntity * item1.item_prc)
print('\nTotal: ${}'.format(tc1),end='\n')
def display_menuProcess(Shopping_Cart):
customerCart = newCart
string=''
menuProcess = ('\nmenuProcess\n'
'a - add item \n'
'r - Delete item \n'
'c - Change item value quanty\n'
'i - Output items\' descrip\n'
'o - result cart_shopping\n'
'q - exit\n')
cmd = ''
while(cmd != 'q'):
string=''
print(menuProcess , end='\n')
cmd = input('Choose an option: ')
while(cmd != 'a' and cmd != 'o' and cmd != 'i' and cmd != 'r'and cmd != 'c' and cmd != 'q'):
cmd = input('Choose an choice: ')
if(cmd == 'a'):
customerCart.additem(string)
if(cmd == 'o'):
customerCart.result_cart()
if(cmd == 'i'):
customerCart.printdescrip()
if(cmd == 'r'):
customerCart.removeitem()
if(cmd == 'c'):
customerCart.modifiedtem()
cust_name = str(input('please Enter cust\'s name: \n'))
currentdate = str(input('\nplease Enter today\'s date: \n'))
print('Customer name:', cust_name , end='\n')
print('Today date:', currentdate , end='\n')
newCart = Shopping_Cart(cust_name, currentdate)
display_menuProcess(newCart)
That is what I have so far.. it only passes the first three.. the rest get errored out..
Screenshot
--------------------------------------------------------------------------------------------------------------
Program
#Create a class Item purchase
class ItemPurchase:
#Constructor
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
#Print item details
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
#To print item description
def print_itemdescription(self):
string = '{}:
{}'.format(self.nameitem, self.item_descrp)
print(string ,
end='\n')
return string
#Create a shopping cart class
class Shopping_Cart:
#Parameter Constructor
def __init__(self, cust_name = 'none',
currentdate = 'January 1, 2017', cartitems = []):
self.cust_name =
cust_name
self.currentdate =
currentdate
self.cartitems =
cartitems
#Add an item
def additem(self, string):
print('\nADD ITEM ' ,
end='\n')
nameitem =
str(input('please Enter item name: '))
item_descrp =
str(input('\n please Enter the item descrpt: '))
item_prc =
int(input('\nplease Enter the item price: '))
item_quntity =
int(input('\n please Enter the item quanty: '))
self.cartitems.append(ItemPurchase(nameitem, item_prc,
item_quntity, item_descrp))
#remove from cart
def removeitem(self):
print('\nREMOVE ITEM
',end='\n')
string =
str(input('please Enter name to delete: '))
i1 = 0
#loop through the
cart
for item1 in
self.cartitems:
if(item1.nameitem ==
string):
del self.cartitems[i1]
flagvalue=True
break
else:
i1 += 1
flagvalue=False
#If not found
if(flagvalue==False):
print('Item could not found . Nothing removed')
#Method to modify quantity of cart
def modifiedtem(self):
print('\nCHANGE
QUANTITY' , end='\n')
name1 =
str(input('please Enter name: '))
#Loop through the
cart
for item1 in
self.cartitems:
if(item1.nameitem == name1):
quantity1 = int(input('please Enter quantity: '))
item1.item_quntity = quantity1
flagvalue=True
break
else:
flagvalue=False
#If not found
if(flagvalue==False):
print('do not be modified')
#Method to find number of items in
cart
def get_numberitems_cart(self):
numitems=0
for item1 in
self.cartitems:
numitems= numitems+item1.item_quntity
return numitems
#Method to get price of the cart
def get_valuecost_of_cart(self):
total_valuecost =
0
valuecost = 0
for item1 in
self.cartitems:
valuecost = (item1.item_quntity * item1.item_prc)
total_valuecost += valuecost
return
total_valuecost
#Display total
def displaytotal():
total_valuecost =
get_valuecost_of_cart()
if (total_valuecost ==
0):
print('empty cart')
else:
result_cart()
#Method to print description of items in
cart
def printdescrip(self):
print('\nOUTPUT values\'
DESCRIPTIONS')
print('{}\'s
cart_shopping - {}'.format(self.cust_name, self.currentdate) ,
end='\n')
print('\nItem desrip' ,
end='\n')
for item1 in
self.cartitems:
print('{}: {}'.format(item1.nameitem, item1.item_descrp) ,
end='\n')
#Print cart
def result_cart(self):
new1=Shopping_Cart()
print('\nOUTPUT',
end='\n')
print('{}\'s
cart_shopping - {}'.format(self.cust_name, self.currentdate))
print('Numb of Items:',
new1.get_numberitems_cart(), end='\n\n')
tc1 = 0
for item1 in
self.cartitems:
print('{} {} @ ${} = ${}'.format(item1.nameitem,
item1.item_quntity,
item1.item_prc, (item1.item_quntity * item1.item_prc)))
tc1 += (item1.item_quntity * item1.item_prc)
print('\nTotal:
${}'.format(tc1),end='\n')
#to display menu for user
def display_menuProcess(Shopping_Cart):
customerCart = newCart
string=''
menuProcess = ('\nmenuProcess\n'
'a - add item \n'
'r - Delete item \n'
'c - Change item value quanty\n'
'i - Output items\' descrip\n'
'o - result cart_shopping\n'
'q - exit\n')
cmd = ''
while(cmd != 'q'):
string=''
print(menuProcess ,
end='\n')
cmd = input('Choose an
option: ')
while(cmd != 'a' and cmd
!= 'o' and cmd != 'i' and cmd != 'r'and cmd != 'c' and cmd !=
'q'):
cmd = input('Choose an choice: ')
if(cmd == 'a'):
customerCart.additem(string)
if(cmd == 'o'):
customerCart.result_cart()
if(cmd == 'i'):
customerCart.printdescrip()
if(cmd == 'r'):
customerCart.removeitem()
if(cmd == 'c'):
customerCart.modifiedtem()
#User input for customer name and date
cust_name = str(input('please Enter cust\'s name: \n'))
currentdate = str(input('\nplease Enter today\'s date: \n'))
print('Customer name:', cust_name , end='\n')
print('Today date:', currentdate , end='\n')
newCart = Shopping_Cart(cust_name, currentdate)
#Call method for menu
display_menuProcess(newCart)
----------------------------------------------------------------------------------
Output
please Enter cust's name:
Michael Merk
please Enter today's date:
12/01/2015
Customer name: Michael Merk
Today date: 12/01/2015
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: a
ADD ITEM
please Enter item name: Biscuit
please Enter the item descrpt: With added flavour and maida
please Enter the item price: 10
please Enter the item quanty: 5
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: a
ADD ITEM
please Enter item name: Chocolate
please Enter the item descrpt: With milk
please Enter the item price: 14
please Enter the item quanty: 2
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: o
OUTPUT
Michael Merk's cart_shopping - 12/01/2015
Numb of Items: 7
Biscuit 5 @ $10 = $50
Chocolate 2 @ $14 = $28
Total: $78
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: r
REMOVE ITEM
please Enter name to delete: Chocolate
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: o
OUTPUT
Michael Merk's cart_shopping - 12/01/2015
Numb of Items: 5
Biscuit 5 @ $10 = $50
Total: $50
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: c
CHANGE QUANTITY
please Enter name: Biscuit
please Enter quantity: 7
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: o
OUTPUT
Michael Merk's cart_shopping - 12/01/2015
Numb of Items: 7
Biscuit 7 @ $10 = $70
Total: $70
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: i
OUTPUT values' DESCRIPTIONS
Michael Merk's cart_shopping - 12/01/2015
Item desrip
Biscuit: With added flavour and maida
menuProcess
a - add item
r - Delete item
c - Change item value quanty
i - Output items' descrip
o - result cart_shopping
q - exit
Choose an option: q
------------------------------------------------------------
Python3 programming help needed LAB*: Program: Online shopping cart (continued) Need the below code edited to...
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...
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,...
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)...
4.18 Ch 7 Program: Online shopping cart (continued) (C++) This program extends the earlier "Online shopping cart" program. (solution from previous lab assignment is provided in Canvas). (1) Extend the ItemToPurchase class per the following specifications: Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt) Public member functions SetDescription() mutator & GetDescription() accessor (2 pts) PrintItemCost() - Outputs the item name followed by the quantity, price, and subtotal PrintItemDescription() -...
Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...
8.7 LAB*: Program: Online shopping cart (Part 2)Note: Creating multiple Scanner objects for the same input stream yields unexpected behavior. Thus, good practice is to use a single Scanner object for reading input from System.in. That Scanner object can be passed as an argument to any methods that read input.This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized...
Ch 7 Program: Online shopping cart (continued) (Java)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class per the following specifications:Private fieldsstring itemDescription - Initialized in default constructor to "none"Parameterized constructor to assign item name, item description, item price, and item quantity (default values of 0). (1 pt)Public member methodssetDescription() mutator & getDescription() accessor (2 pts)printItemCost() - Outputs the item name followed by the quantity, price, and subtotalprintItemDescription() - Outputs the...
11.12 LAB*: Program: Online shopping cart (continued)This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program).(1) Extend the ItemToPurchase class to contain a new attribute. (2 pts)item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class.print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter.Ex. of print_item_description() output:Bottled Water: Deer Park, 12 oz.(2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs...
PYTHON The provided code in the ATM program is incomplete. Complete the run method of the ATM class. The program should display a message that the police will be called after a user has had three successive failures. The program should also shut down the bank when this happens. [comment]: <> (The ATM program allows a user an indefinite number of attempts to log in. Fix the program so that it displays a message that the police will be called...
Python 3 Question: All I need is for someone to edit the program with comments that explains what the program is doing (for the entire program) def main(): developerInfo() #i left this part out retail = Retail_Item() test = Cash_Register() test.data(retail.get_item_number(), retail.get_description(), retail.get_unit_in_inventory(), retail.get_price()) answer = 'n' while answer == 'n' or answer == 'N': test.Menu() print() print() Number = int(input("Enter the menu number of the item " "you would like to purchase: ")) if Number == 8: test.show_items() else:...