Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!

glass
pen
clip
papers
heaphones

CMPSC 206 Ch 9 Program Online shopping Cart Python Assignment

CMPSC 206 Ch 9 Program Online shopping Cart Python Assignment

CMPSC 206 Ch 9 Program Online shopping Cart Python Assignment
Question Description
LAB
ACTIVITY
16.23.1: Ch 9 Program: Online shopping cart (continued) (Python 3)
1 / 29
main.py
Load default template”¦
class ItemToPurchase:
def __init__(self, item_name= “˜none’, item_price=0, item_quantity=0, item_description = “˜none’):
self.item_name = item_name
self.item_price = item_price
self.item_quantity = item_quantity
self.item_description = item_description
def print_item_cost(self):
string = “˜{} {} @ ${} = ${}’.format(self.item_name, self.item_quantity, self.item_price, (self.item_quantity
* self.item_price))
cost = self.item_quantity * self.item_price
return string, cost
def print_item_description(self):
string = “˜{}: {}’.format(self.item_name, self.item_description)
print(string, end=’ “˜)
return string
class ShoppingCart:
def __init__(self,customer_name= None ,current_date=’January 1,2016″²,cart_items=[]):
self.customer_name = customer_name
self.current_date = current_date
self.cart_items = cart_items
def add_item(self,):
print(“˜nADD ITEM TO CART’, end=’n’)
#prompt the name and description of item,price and Quentity
item_name = str(input(“˜Enter the item name:’));
item_description = str(input(“˜nEnter the item description:’));
item_price = int(input(“˜nEnter the item price:’));
item_quantity = int(input(“˜nEnter the item quantity:n’))
#Append the above values in to the list
self.cart_items.append(ItemToPurchase(item_name, item_price, item_quantity, item_description))
#Implement the method to delete the item in the cart
def remove_item(self):
print()
print(“˜REMOVE ITEM FROM CART’, end=’n’)
#prompt the item to remove the list
string = str(input(“˜Enter name of item to remove:n’))
i = 0
#Using for-loop to iterate every item
for item in self.cart_items:
#If item found delete in the list
if(item.item_name == string):
del self.cart_items[i]
i += 1
#set the flag value to true
#break from the list
flag=True
break
#Otherwiese set value to false
else:
flag=False
#IF the value not found
if(flag==False):
#print the message
print(“˜Item not found in cart. Nothing removed.’)
def modify_item(self):
print(“˜nCHANGE ITEM QUANTITY’, end=’n’)
#Prompt the input item
name = str(input(“˜Enter the item name:’))
#Using for-loop to iterate every item
for item in self.cart_items:
#If item found update Quantity in the list
if(item.item_name == name):
quantity = int(input(“˜Enter the new quantity:’))
item.item_quantity = quantity
#set the flag value to true
#break from the list
flag=True
break
#Otherwiese set value to false
else:
flag=False
#IF the value not found
if(flag==False):
#print the message
print(“˜Item not found in cart. Nothing modified.’)
#implement method to compute total number of items in the cart
def get_num_items_in_cart(self):
num_items = 0
#Using for-loop to iterate the cart
for item in self.cart_items:
#ADD the Quantities
num_items += item.item_quantity
#return the num_Items
return num_items
#Implement the method
def get_cost_of_cart(self):
total_cost = 0
cost = 0
#Using for-loop to iterate the list
#mulitply the price and Quantity
#add value to the Total_Cost
for item in self.cart_items:
cost = (item.item_quantity * item.item_price)
total_cost += cost
#return the value
return total_cost
#Implement the method to print the total
def print_total():
total_cost = self.get_cost_of_cart()
if (total_cost == 0):
print(“˜SHOPPING CART IS EMPTY’)
else:
output_cart()
#Implement the method to print_descriptions
def print_descriptions(self):
print(“˜OUTPUT ITEMS’ DESCRIPTIONS’)
print(“˜{}’s Shopping Cart – {}’.format(self.customer_name, self.current_date),end=’n’)
print(“˜nItem Descriptions’, end=’n’)
for item in self.cart_items:
print(“˜{}: {}’.format(item.item_name, item.item_description), end=’n’)
#Implement the method output_cart()
def output_cart(self):
new=ShoppingCart()
print(“˜OUTPUT SHOPPING CART’, end=’n’)
print(“˜{}’s Shopping Cart – {}’.format(self.customer_name, self.current_date),end=’n’)
print(“˜Number of Items:’, new.get_num_items_in_cart(), end=’nn’)
self.total_cost = self.get_cost_of_cart()
if (self.total_cost == 0):
print(“˜SHOPPING CART IS EMPTY’)
else:
pass
tc = 0
for item in self.cart_items:
print(“˜{} {} @ ${} = ${}’.format(item.item_name, item.item_quantity,
item.item_price, (item.item_quantity * item.item_price)), end=’n’)
tc += (item.item_quantity * item.item_price)
print(“˜nTotal: ${}’.format(tc), end=’n’)
#Implement the method print_menu
def print_menu(new_cart):
customer_Cart = newCart
string=”
#declare the string menu
menu = (“˜nMENUn’
“˜a – Add item to cartn’
“˜r – Remove item from cartn’
“˜c – Change item quantityn’
“˜i – Output items’ descriptionsn’
“˜o – Output shopping cartn’
“˜q – Quitn’)
command = “
#Using while loop
#to iterate until user enters q
while(command != “˜q’):
string=”
print(“˜nMENUn’
“˜a “

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Eminence Papers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Eminence Papers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Eminence Papers is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Eminence Papers, we have put in place a team of experts who answer to all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.

Phoenix Papers Inc.

Your one stop solution for all your online studies solutions. Hire some of the world's highly rated writers to handle your writing assignments. And guess what, you don't have to break the bank.

© 2021 Phoenix Papers Inc.