9.12 Ch 9 Program: The Evil Register Python 3.7
"The ItemToPurchase class
If you haven't done so already, make sure to complete zyLab 9.11 before this one. Otherwise, you will have to implement the ItemToPurchase class from scratch and this zyLab won't make much sense".
ItemToPurchase class from zyLab 9.11 refers to:
(1) Build the ItemToPurchase class with the following specifications:
Attributes (3 pts)
item_name (string)
item_price (int)
item_quantity (int)
Default constructor (1 pt)
Initializes item's name = "none", item's price = 0, item's quantity = 0
Method
print_item_cost()
Screenshot
---------------------------------------------------
Program
from datetime import date
#Create a class for items
class Itemtopurchase:
#Attributes
item_name="none"
item_price=0
item_quantity=0
#constructor
def
__init__(self,item_name,item_price,item_quantity):
self.item_name=item_name
self.item_price=item_price
self.item_quantity=item_quantity
#Method to print item details
def print_item_cost(self):
print(self.item_name+"
"+str(self.item_quantity)+" @ $"+str(self.item_price)+" =
$"+str(self.item_price*self.item_quantity))
#Getters
def get_item_price(self):
return
self.item_price
def get_item_quantity(self):
return
self.item_quantity
#Create receipt class
class Receipt:
#attributes
customer_name=""
purchase_date=""
cart_items=[]
#constructor
def
__init__(self,customer_name,purchase_date):
if
customer_name=="":
self.customer_name="Real Human"
else:
self.customer_name=customer_name
if
purchase_date=="":
self.purchase_date=str(date.today())
else:
self.purchase_date=purchase_date
#add items
def add_item(self,item):
self.cart_items.append(item)
#Print details
def print_receipt(self,isevil):
total=0
if isevil==True:
self.cart_items=sorted(self.cart_items, key=lambda
cart:(cart.get_item_quantity()*cart.get_item_price()))
print("Welcome to EvilMart, "+self.customer_name)
print(self.purchase_date)
print("Have an EVIL day!")
else:
self.cart_items=sorted(self.cart_items, key=lambda
cart:(cart.get_item_quantity()*cart.get_item_price()),reverse=True)
print("Welcome to GoodCo, "+self.customer_name)
print(self.purchase_date)
print("Have an GOOD day!")
for x in
self.cart_items:
x.print_item_cost()
total+=x.get_item_price()*x.get_item_quantity()
print("Total:
$"+str(total))
#Main method
def main():
#Promt for customer name and date
customer_name=input("Enter Customer
Name:\n")
purchase_date=input("Enter Today's Date:
\n")
#Evil prompt
isEvil=input("Are you evil?\n")
isEvil=isEvil.upper()
evilCheck=False
if("YEAH" in isEvil or "YES" in isEvil or "YUP"
in isEvil):
evilCheck=True
#Receipt object
receipt=Receipt(customer_name,purchase_date)
#Loop unti user stop purchase
while True:
item_name=input("Enter
the item name: \n")
if item_name!="":
item_price=int(input("Enter the item price: \n"))
item_quantity=int(input("enter the item quantity: \n"))
receipt.add_item(Itemtopurchase(item_name,item_price,item_quantity))
else:
print()
receipt.print_receipt(evilCheck)
break
#star
main()
---------------------------------------------------------------------
output
Enter Customer Name:
Nate
Enter Today's Date:
Are you evil?
bwahahah yes
Enter the item name:
Bottles Children Tears
Enter the item price:
2
enter the item quantity:
299
Enter the item name:
Salt
Enter the item price:
2
enter the item quantity:
1
Enter the item name:
Welcome to EvilMart, Nate
2019-06-02
Have an EVIL day!
Salt 1 @ $2 = $2
Bottles Children Tears 299 @ $2 = $598
Total: $600
-------------------------------------------------
Program Screenshot
9.12 Ch 9 Program: The Evil Register Python 3.7 "The ItemToPurchase class If you haven't done so already, make s...
(1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (2 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10 (2) In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. (4 pts) Ex: Item 1 Enter the item name: Chocolate...
11.11 LAB: Warm up: Online shopping cart (1) Build the ItemToPurchase class with the following specifications: Attributes (6 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (2 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Ex. of print_item_cost() output: Bottled Water 10 @ $1 = $10 (2) In the main section of your code, prompt the user for two items and create two objects of the ItemToPurchase class. (4 pts) Ex:...
*Urgent* I've tried getting help with this a couple times, but nobody has answered my questions, and it's been several days. #################################################################################### This needs to be Python that works in a Zybooks programming window. 1. Build an ItemToPurchase class with the following specifications: Attributes (3 pts) item_name (string) item_price (float) item_quantity (int) Default constructor (1 pt) Initializes item's name = "none", item's price = 0, item's quantity = 0 Method print_item_cost() Example of print_item_cost() output: Bottled Water 10 @ $1...
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,...