Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class ItemToPurchase:
- def __init__(self, item_name='none', item_description='none', item_price=0, item_quantity=0):
- self.item_name = item_name
- self.item_description = item_description
- self.item_price = item_price
- self.item_quantity = item_quantity
- return
- def print_item_cost(self):
- 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)))
- class ShoppingCart:
- def __init__(self, customer_name='none', current_date='January 1, 2016', cart_items=[]):
- self.customer_name = customer_name
- self.current_date = current_date
- self.cart_items = cart_items
- def add_item(self):
- print ('ADD ITEM TO CART')
- thirdItem = ItemToPurchase()
- thirdItem.item_name = input('Enter the item name:\n')
- self.cart_items.append(thirdItem.item_name)
- thirdItem.item_description = input('Enter the item description:\n')
- self.cart_items.append(thirdItem.item_description)
- thirdItem.item_price = float(input('Enter the item price:\n'))
- self.cart_items.append(thirdItem.item_price)
- thirdItem.item_quantity = int(input('Enter the item quantity:\n'))
- self.cart_items.append(thirdItem.item_quantity)
- print ('')
- print ('MENU')
- print ('a - Add item to cart')
- print ('r - Remove item from cart')
- print ('c - Change item quantity')
- print ('i - Output items\' descriptions')
- print ('o - Output shopping cart')
- print ('q - Quit')
- print ('')
- def remove_item(self):
- print ('REMOVE ITEM FROM CART')
- item_remove = ''
- item_remove = input('Enter name of item to remove:\n')
- if item_remove in self.cart_items:
- list_index = self.cart_items.index(item_remove)
- self.cart_items.pop(list_index)
- self.cart_items.pop(list_index)
- self.cart_items.pop(list_index)
- self.cart_items.pop(list_index)
- print ('')
- else:
- print ('Item not found in cart. Nothing removed.')
- print ('')
- print ('MENU')
- print ('a - Add item to cart')
- print ('r - Remove item from cart')
- print ('c - Change item quantity')
- print ('i - Output items\' descriptions')
- print ('o - Output shopping cart')
- print ('q - Quit')
- print ('')
- def modify_item(self):
- print ('CHANGE ITEM QUANTITY')
- item_name = ''
- item_name = input('Enter the item name:\n')
- new_quantity = ''
- new_quantity = int(input('Enter the new quantity:\n'))
- if item_name in self.cart_items:
- quantity_index = (self.cart_items.index(item_name) + 3)
- self.cart_items.insert(quantity_index, new_quantity)
- self.cart_items.pop(quantity_index + 1)
- print ('')
- else:
- print ('Item not found in cart. Nothing modified.')
- print ('')
- print ('MENU')
- print ('a - Add item to cart')
- print ('r - Remove item from cart')
- print ('c - Change item quantity')
- print ('i - Output items\' descriptions')
- print ('o - Output shopping cart')
- print ('q - Quit')
- print ('')
- def get_num_items_in_cart(self):
- if len(self.cart_items) == 0:
- print ('Number of Items:', len(self.cart_items))
- elif len(self.cart_items) == 4:
- print ('Number of Items: %d' % (self.cart_items[3]))
- elif len(self.cart_items) == 8:
- print ('Number of Items: %d' % ((self.cart_items[3] + self.cart_items[7])))
- elif len(self.cart_items) == 12:
- print ('Number of Items: %d' % ((self.cart_items[3] + self.cart_items[7] + self.cart_items[11])))
- else:
- pass
- print ('')
- if len(self.cart_items) > 0:
- if len(self.cart_items) < 5:
- 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])))
- elif len(self.cart_items) < 9:
- 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])))
- 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])))
- elif len(self.cart_items) < 13:
- 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])))
- 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])))
- 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])))
- else:
- print ('SHOPPING CART IS EMPTY')
- def get_cost_of_cart():
- pass
- def print_total(self):
- if len(self.cart_items) > 0:
- if len(self.cart_items) < 5:
- print ('')
- print ('Total: $%.0f' % ((self.cart_items[2] * self.cart_items[3])))
- print ('')
- elif len(self.cart_items) < 9:
- print ('')
- print ('Total: $%.0f' % ((self.cart_items[2] * self.cart_items[3]) + (self.cart_items[6] * self.cart_items[7])))
- print ('')
- elif len(self.cart_items) < 13:
- print ('')
- 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])))
- print ('')
- else:
- print ('')
- print ('Total: $0')
- print ('')
- print ('MENU')
- print ('a - Add item to cart')
- print ('r - Remove item from cart')
- print ('c - Change item quantity')
- print ('i - Output items\' descriptions')
- print ('o - Output shopping cart')
- print ('q - Quit')
- print ('')
- def print_descriptions(self):
- print ('OUTPUT ITEMS\' DESCRIPTIONS')
- print ('%s\'s Shopping Cart - %s' % (my_cart.customer_name, my_cart.current_date))
- print ('')
- print ('Item Descriptions')
- if len(self.cart_items) > 0:
- if len(self.cart_items) < 5:
- print ('%s: %s' % (self.cart_items[0], self.cart_items[1]))
- elif len(self.cart_items) < 9:
- print ('%s: %s' % (self.cart_items[0], self.cart_items[1]))
- print ('%s: %s' % (self.cart_items[4], self.cart_items[5]))
- elif len(self.cart_items) < 13:
- print ('%s: %s' % (self.cart_items[0], self.cart_items[1]))
- print ('%s: %s' % (self.cart_items[4], self.cart_items[5]))
- print ('%s: %s' % (self.cart_items[8], self.cart_items[9]))
- else:
- pass
- print ('')
- print ('MENU')
- print ('a - Add item to cart')
- print ('r - Remove item from cart')
- print ('c - Change item quantity')
- print ('i - Output items\' descriptions')
- print ('o - Output shopping cart')
- print ('q - Quit')
- print ('')
- return
- #-------------------------------------------------------------------------------
- menuInput = ''
- def print_menu(ShoppingCart):
- print ('MENU')
- print ('a - Add item to cart')
- print ('r - Remove item from cart')
- print ('c - Change item quantity')
- print ('i - Output items\' descriptions')
- print ('o - Output shopping cart')
- print ('q - Quit')
- print ('')
- menuInput = ''
- while menuInput != 'q':
- menuInput = input ('Choose an option:\n')
- if menuInput == 'a':
- my_cart.add_item()
- elif menuInput == 'r':
- my_cart.remove_item()
- elif menuInput == 'c':
- my_cart.modify_item()
- elif menuInput == 'i':
- my_cart.print_descriptions()
- elif menuInput == 'o':
- print ('OUTPUT SHOPPING CART')
- print ('%s\'s Shopping Cart - %s' % (my_cart.customer_name, my_cart.current_date))
- my_cart.get_num_items_in_cart()
- my_cart.print_total()
- else:
- continue
- if __name__ == '__main__':
- my_cart = ShoppingCart()
- my_cart.customer_name = input('Enter customer\'s name:\n')
- my_cart.current_date = input('Enter today\'s date:\n')
- print ('')
- print ('Customer name:', my_cart.customer_name)
- print ('Today\'s date:', my_cart.current_date)
- print ('')
- print_menu(ShoppingCart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement