N3rdlove

Final Project

May 3rd, 2022 (edited)
354
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #Gregory Houston, CIS-115, 05/03/2022, User input grocery list
  2.  
  3. #Defining Class and Attributes
  4. class Item:
  5. def __init__(self):
  6. self.item_name = str('')
  7. self.item_price = float(0)
  8. self.item_quantity = int(0)
  9. def print_item_cost(self):
  10. print(self.item_name, end = ' ')
  11. print(self.item_quantity, '@ $', self.item_price, '= $', (self.item_quantity * self.item_price))
  12. if __name__ == "__main__": #First Instance calling class (Req. user input)
  13. print('Item 1')
  14. name = input('Enter item name:\n') #User input item name
  15. price = float(input('Enter item price:\n')) #User input item price
  16. quantity = int(input('Enter item quantity:\n')) #User input item quantity
  17. item1 = Item() #Calls Class
  18. item1.item_name = name #Assign user value for item name
  19. item1.item_price = price #Assign user value for item price
  20. item1.item_quantity = quantity #Assign user value for item quantity
  21. #Second instance (Req. user input)
  22. print('Item 2')
  23. name = input('Enter item name:\n') #User input item name
  24. price = float(input('Enter item price:\n')) #User input item price
  25. quantity = int(input('Enter item quantity:\n')) #User input item quantity
  26. item2 = Item() #Calls Class
  27. item2.item_name = name #Assign user value for name
  28. item2.item_price = price #Assign user value for price
  29. item2.item_quantity = quantity #Assign user value for quantity
  30.  
  31. #Assigns total_cost with Item1 price X Item2 price
  32. total_cost = (item1.item_price * item1.item_quantity) + (item2.item_price * item2.item_quantity)
  33.  
  34. print('TOTAL COST') #Prints TOTAL COST
  35. print(item1.print_item_cost(), '\n') #Output for Item 1
  36. print(item2.print_item_cost(), '\n') #Output for Item 2
  37. print('Total:', f'{total_cost:.2f}') #Returns Grand Total
  38.  
Add Comment
Please, Sign In to add comment