Advertisement
ReroReroDaze

Untitled

Apr 25th, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.83 KB | None | 0 0
  1. class ItemToPurchase:
  2.    
  3.     def __init__(self, item_name='none', item_description='none', item_price=0, item_quantity=0):
  4.         self.item_name = item_name
  5.         self.item_description = item_description
  6.         self.item_price = item_price
  7.         self.item_quantity = item_quantity
  8.         return
  9.  
  10.     def print_item_cost(self):
  11.         return print ('%s %d %s @ $%.0f = $%.0f' % (self.item_name, self.item_quantity, self.item_description, self.item_price, (self.item_price * self.item_quantity)))
  12.        
  13.  
  14. class ShoppingCart:
  15.  
  16.     def __init__(self, customer_name='none', current_date='January 1, 2016', cart_items=[]):
  17.         self.customer_name = customer_name
  18.         self.current_date = current_date
  19.         self.cart_items = cart_items
  20.  
  21.     def add_item(self):
  22.         print ('ADD ITEM TO CART')
  23.         thirdItem = ItemToPurchase()
  24.         thirdItem.item_name = input('Enter the item name:\n')
  25.         self.cart_items.append(thirdItem.item_name)
  26.         thirdItem.item_description = input('Enter the item description:\n')
  27.         self.cart_items.append(thirdItem.item_description)
  28.         thirdItem.item_price = float(input('Enter the item price:\n'))
  29.         self.cart_items.append(thirdItem.item_price)
  30.         thirdItem.item_quantity = int(input('Enter the item quantity:\n'))
  31.         self.cart_items.append(thirdItem.item_quantity)
  32.         print ('')
  33.         print ('MENU')
  34.         print ('a - Add item to cart')
  35.         print ('r - Remove item from cart')
  36.         print ('c - Change item quantity')
  37.         print ('i - Output items\' descriptions')
  38.         print ('o - Output shopping cart')
  39.         print ('q - Quit')
  40.         print ('')
  41.     def remove_item(self):
  42.         print ('REMOVE ITEM FROM CART')
  43.         item_remove = ''
  44.         item_remove = input('Enter name of item to remove:\n')
  45.         if item_remove in self.cart_items:
  46.             list_index = self.cart_items.index(item_remove)
  47.             self.cart_items.pop(list_index)
  48.             self.cart_items.pop(list_index)
  49.             self.cart_items.pop(list_index)
  50.             self.cart_items.pop(list_index)
  51.             print ('')
  52.         else:
  53.             print ('Item not found in cart. Nothing removed.')
  54.             print ('')
  55.         print ('MENU')
  56.         print ('a - Add item to cart')
  57.         print ('r - Remove item from cart')
  58.         print ('c - Change item quantity')
  59.         print ('i - Output items\' descriptions')
  60.         print ('o - Output shopping cart')
  61.         print ('q - Quit')
  62.         print ('')
  63.     def modify_item(self):
  64.         print ('CHANGE ITEM QUANTITY')
  65.         item_name = ''
  66.         item_name = input('Enter the item name:\n')
  67.         new_quantity = ''
  68.         new_quantity = int(input('Enter the new quantity:\n'))
  69.         if item_name in self.cart_items:
  70.             quantity_index = (self.cart_items.index(item_name) + 3)
  71.             self.cart_items.insert(quantity_index, new_quantity)
  72.             self.cart_items.pop(quantity_index + 1)
  73.             print ('')
  74.         else:
  75.             print ('Item not found in cart. Nothing modified.')
  76.             print ('')
  77.         print ('MENU')
  78.         print ('a - Add item to cart')
  79.         print ('r - Remove item from cart')
  80.         print ('c - Change item quantity')
  81.         print ('i - Output items\' descriptions')
  82.         print ('o - Output shopping cart')
  83.         print ('q - Quit')
  84.         print ('')
  85.     def get_num_items_in_cart(self):
  86.         if len(self.cart_items) == 0:
  87.             print ('Number of Items:', len(self.cart_items))
  88.         elif len(self.cart_items) == 4:
  89.             print ('Number of Items: %d' % (self.cart_items[3]))
  90.         elif len(self.cart_items) == 8:
  91.             print ('Number of Items: %d' % ((self.cart_items[3] + self.cart_items[7])))
  92.         elif len(self.cart_items) == 12:
  93.             print ('Number of Items: %d' % ((self.cart_items[3] + self.cart_items[7] + self.cart_items[11])))
  94.         else:
  95.             pass
  96.         print ('')
  97.         if len(self.cart_items) > 0:
  98.             if len(self.cart_items) < 5:
  99.                 print ('%s %d @ $%.0f = $%.0f' % (self.cart_items[0], self.cart_items[3], self.cart_items[2], (self.cart_items[2] * self.cart_items[3])))
  100.             elif len(self.cart_items) < 9:
  101.                 print ('%s %d @ $%.0f = $%.0f' % (self.cart_items[0], self.cart_items[3], self.cart_items[2], (self.cart_items[2] * self.cart_items[3])))
  102.                 print ('%s %d @ $%.0f = $%.0f' % (self.cart_items[4], self.cart_items[7], self.cart_items[6], (self.cart_items[6] * self.cart_items[7])))
  103.             elif len(self.cart_items) < 13:
  104.                 print ('%s %d @ $%.0f = $%.0f' % (self.cart_items[0], self.cart_items[3], self.cart_items[2], (self.cart_items[2] * self.cart_items[3])))
  105.                 print ('%s %d @ $%.0f = $%.0f' % (self.cart_items[4], self.cart_items[7], self.cart_items[6], (self.cart_items[6] * self.cart_items[7])))
  106.                 print ('%s %d @ $%.0f = $%.0f' % (self.cart_items[8], self.cart_items[11], self.cart_items[10], (self.cart_items[10] * self.cart_items[11])))
  107.         else:
  108.             print ('SHOPPING CART IS EMPTY')
  109.     def get_cost_of_cart():
  110.         pass
  111.     def print_total(self):
  112.         if len(self.cart_items) > 0:
  113.             if len(self.cart_items) < 5:
  114.                 print ('')
  115.                 print ('Total: $%.0f' % ((self.cart_items[2] * self.cart_items[3])))
  116.                 print ('')
  117.             elif len(self.cart_items) < 9:
  118.                 print ('')
  119.                 print ('Total: $%.0f' % ((self.cart_items[2] * self.cart_items[3]) + (self.cart_items[6] * self.cart_items[7])))
  120.                 print ('')
  121.             elif len(self.cart_items) < 13:
  122.                 print ('')
  123.                 print ('Total: $%.0f' % ((self.cart_items[2] * self.cart_items[3]) + (self.cart_items[6] * self.cart_items[7]) + (self.cart_items[10] * self.cart_items[11])))
  124.                 print ('')
  125.         else:
  126.             print ('')
  127.             print ('Total: $0')
  128.             print ('')
  129.         print ('MENU')
  130.         print ('a - Add item to cart')
  131.         print ('r - Remove item from cart')
  132.         print ('c - Change item quantity')
  133.         print ('i - Output items\' descriptions')
  134.         print ('o - Output shopping cart')
  135.         print ('q - Quit')
  136.         print ('')
  137.     def print_descriptions(self):
  138.         print ('OUTPUT ITEMS\' DESCRIPTIONS')
  139.         print ('%s\'s Shopping Cart - %s' % (my_cart.customer_name, my_cart.current_date))
  140.         print ('')
  141.         print ('Item Descriptions')
  142.         if len(self.cart_items) > 0:
  143.             if len(self.cart_items) < 5:
  144.                 print ('%s: %s' % (self.cart_items[0], self.cart_items[1]))
  145.             elif len(self.cart_items) < 9:
  146.                 print ('%s: %s' % (self.cart_items[0], self.cart_items[1]))
  147.                 print ('%s: %s' % (self.cart_items[4], self.cart_items[5]))
  148.             elif len(self.cart_items) < 13:
  149.                 print ('%s: %s' % (self.cart_items[0], self.cart_items[1]))
  150.                 print ('%s: %s' % (self.cart_items[4], self.cart_items[5]))
  151.                 print ('%s: %s' % (self.cart_items[8], self.cart_items[9]))
  152.         else:
  153.             pass
  154.         print ('')
  155.         print ('MENU')
  156.         print ('a - Add item to cart')
  157.         print ('r - Remove item from cart')
  158.         print ('c - Change item quantity')
  159.         print ('i - Output items\' descriptions')
  160.         print ('o - Output shopping cart')
  161.         print ('q - Quit')
  162.         print ('')
  163.         return
  164.  
  165. #-------------------------------------------------------------------------------
  166. menuInput = ''
  167.  
  168. def print_menu(ShoppingCart):
  169.     print ('MENU')
  170.     print ('a - Add item to cart')
  171.     print ('r - Remove item from cart')
  172.     print ('c - Change item quantity')
  173.     print ('i - Output items\' descriptions')
  174.     print ('o - Output shopping cart')
  175.     print ('q - Quit')
  176.     print ('')
  177.     menuInput = ''
  178.     while menuInput != 'q':
  179.         menuInput = input ('Choose an option:\n')
  180.         if menuInput == 'a':
  181.             my_cart.add_item()
  182.         elif menuInput == 'r':
  183.             my_cart.remove_item()
  184.         elif menuInput == 'c':
  185.             my_cart.modify_item()
  186.         elif menuInput == 'i':
  187.             my_cart.print_descriptions()
  188.         elif menuInput == 'o':
  189.             print ('OUTPUT SHOPPING CART')
  190.             print ('%s\'s Shopping Cart - %s' % (my_cart.customer_name, my_cart.current_date))
  191.             my_cart.get_num_items_in_cart()
  192.             my_cart.print_total()
  193.         else:
  194.             continue
  195.  
  196. if __name__ == '__main__':
  197.     my_cart = ShoppingCart()
  198.    
  199.     my_cart.customer_name = input('Enter customer\'s name:\n')
  200.     my_cart.current_date = input('Enter today\'s date:\n')
  201.     print ('')
  202.    
  203.     print ('Customer name:', my_cart.customer_name)
  204.     print ('Today\'s date:', my_cart.current_date)
  205.     print ('')
  206.    
  207.     print_menu(ShoppingCart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement