What are some different ways/methods I can go about adding the costs of these two items using the code below?
Using Python: What are some different ways/methods I can go about adding the costs of these two items using the code below?
class ItemToPurchase:
def __init__(self):
self.item_name = "none"
self.item_price = 0
self.item_quantity = 0
def print_item_cost(self):
print (f'Bottled Water {self.item_quantity} @ ${self.item_price} = ${self.item_price * self.item_quantity}')
if __name__ == "__main__":
print ("Item 1")
theName = input ("Enter the item name:\n")
thePrice = int(input("Enter the item price:\n") )
theQty = int(input("Enter the item quantity:\n") )
aNewObject = ItemToPurchase()
aNewObject.item_name = theName
aNewObject.item_price = thePrice
aNewObject.item_quantity = theQty
#aNewObject.print_item_cost()
print()
print ("Item 2")
theName = input ("Enter the item name:\n")
thePrice = int(input("Enter the item price:\n") )
theQty = int(input("Enter the item quantity:\n") )
anotherObject = ItemToPurchase()
anotherObject.item_name = theName2
anotherObject.item_price = thePrice2
anotherObject.item_quantity = theQty2
#anotherObject.print_item_cost()
print("\nTOTAL COST")

Trending now
This is a popular solution!
Step by step
Solved in 4 steps









