Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Gregory Houston, CIS-115, 05/03/2022, User input grocery list
- #Defining Class and Attributes
- class Item:
- def __init__(self):
- self.item_name = str('')
- self.item_price = float(0)
- self.item_quantity = int(0)
- def print_item_cost(self):
- print(self.item_name, end = ' ')
- print(self.item_quantity, '@ $', self.item_price, '= $', (self.item_quantity * self.item_price))
- if __name__ == "__main__": #First Instance calling class (Req. user input)
- print('Item 1')
- name = input('Enter item name:\n') #User input item name
- price = float(input('Enter item price:\n')) #User input item price
- quantity = int(input('Enter item quantity:\n')) #User input item quantity
- item1 = Item() #Calls Class
- item1.item_name = name #Assign user value for item name
- item1.item_price = price #Assign user value for item price
- item1.item_quantity = quantity #Assign user value for item quantity
- #Second instance (Req. user input)
- print('Item 2')
- name = input('Enter item name:\n') #User input item name
- price = float(input('Enter item price:\n')) #User input item price
- quantity = int(input('Enter item quantity:\n')) #User input item quantity
- item2 = Item() #Calls Class
- item2.item_name = name #Assign user value for name
- item2.item_price = price #Assign user value for price
- item2.item_quantity = quantity #Assign user value for quantity
- #Assigns total_cost with Item1 price X Item2 price
- total_cost = (item1.item_price * item1.item_quantity) + (item2.item_price * item2.item_quantity)
- print('TOTAL COST') #Prints TOTAL COST
- print(item1.print_item_cost(), '\n') #Output for Item 1
- print(item2.print_item_cost(), '\n') #Output for Item 2
- print('Total:', f'{total_cost:.2f}') #Returns Grand Total
Add Comment
Please, Sign In to add comment