Guest User

Untitled

a guest
Dec 7th, 2019
133
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class ItemToPurchase:
  2. # default costructor
  3. def __init__(self):
  4. # attributes
  5. self.item_name = "none"
  6. self.item_price = 0.0
  7. self.item_quantity = 0
  8.  
  9. # method
  10. def print_item_cost(self):
  11. print(self.item_name + " " + str(self.item_quantity) + " @ $" + str(self.item_price) + " = $" + str(
  12. self.item_price * self.item_quantity))
  13.  
  14.  
  15. if __name__ == "__main__":
  16. # prompt user for two items
  17. print("Item 1")
  18. item1 = ItemToPurchase()
  19. item1.item_name = input("Enter the item name:\n")
  20. item1.item_price = int(input("Enter the item price:\n"))
  21. item1.item_quantity = int(input("Enter the item quantity:\n"))
  22.  
  23. # prompt item 2
  24. print("\nItem 2")
  25. item2 = ItemToPurchase()
  26. item2.item_name = input("Enter the item name:\n")
  27. item2.item_price = int(input("Enter the item price:\n"))
  28. item2.item_quantity = int(input("Enter the item quantity:\n"))
  29.  
  30. # print info
  31. total_cost = item1.item_price * item1.item_quantity + item2.item_price * item2.item_quantity
  32.  
  33. print("\nTOTAL COST")
  34. item1.print_item_cost()
  35. item2.print_item_cost()
  36.  
  37. print("\nTotal: $" + str(total_cost))
RAW Paste Data