Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- ItemToPurchase = collections.namedtuple('ItemToPurchase', 'item_name item_quantity item_price item_description')
- def construct_item():
- global new_item
- new_item = ItemToPurchase(item_name = 'none', item_quantity = 0, item_price = 0, item_description = 'none' )
- #print(new_item)
- return new_item
- def print_item_cost(new_item1,new_item2):
- total1 = new_item1[1] * new_item1[2]
- total2 = new_item2[1] * new_item2[2]
- print()
- print('TOTAL COST')
- print('%s %.0f @ $%d = $' % new_item1[0:3] + str(int(total1)))
- print('%s %.0f @ $%d = $' % new_item2[0:3] + str(int(total2)))
- print()
- added_total = int(total1) + int(total2)
- print('Total: $%d' % added_total)
- #def print_item_description():
- # print('%s : %s' % new_item1[0] + newitem1[4])
- ShoppingCart = collections.namedtuple('ShoppingCart', 'customer_name current_date cart_items')
- def construct_cart():
- global ShoppingCart
- ShoppingCart = ShoppingCart(customer_name = 'none', current_date = 'January 1, 2016', cart_items = [])
- return ShoppingCart
- def print_menu():
- menu = '''MENU
- a - Add item to cart
- r - Remove item from cart
- c - Change item quantity
- i - Output items\' descriptions
- o - Output shopping cart
- q - Quit'''
- print(menu)
- print()
- menu_option = input('Choose an option:\n')
- while menu_option != 'q':
- if menu_option == 'a':
- add_item(ShoppingCart,ItemToPurchase)
- print()
- print(menu)
- print()
- elif menu_option == 'o':
- print_total(ShoppingCart)
- print(menu)
- print()
- menu_option = input('Choose an option:\n')
- def add_item(ShoppingCart, ItemToPurchase):
- new_item = construct_item()
- cart_items = ShoppingCart[2]
- print('ADD ITEM TO CART')
- add_name = input('Enter the item name:\n')
- add_description = input('Enter the item description:\n')
- add_price = int(input('Enter the item price:\n'))
- add_quantity = int(input('Enter the item quantity:\n'))
- new_item = new_item._replace(item_name = add_name, item_price = add_price, item_quantity = add_quantity, item_description = add_description)
- cart_items.append(new_item)
- #print(ShoppingCart)
- def print_total(ShoppingCart):
- cart_items = ShoppingCart[2]
- print('OUTPUT SHOPPING CART')
- print("%s's Shopping Cart - %s" % (ShoppingCart[0],ShoppingCart[1]))
- if cart_items == []:
- print('Number of Items: %d\n' % len(ShoppingCart[2]))
- print('SHOPPING CART IS EMPTY\n')
- print('Total: $0\n')
- else:
- print('Number of Items: %d\n' % cart_items[0][1])
- #FIXME Write a For loop so that it goes through all the carts items.
- total = cart_items[0][1] * cart_items[0][2]
- print('%s %d @ $%d = $' % cart_items[0][0:3] + str(total))
- print()
- print('Total: $%d' % total)
- print()
- if __name__ == "__main__":
- # Type main section of code here
- #print_item_cost(new_item)
- new_customer = input('Enter customer\'s name:\n')
- date = input('Enter today\'s date:\n')
- construct_cart()
- ShoppingCart = ShoppingCart._replace(customer_name = new_customer, current_date = date)
- #print(ShoppingCart)
- print()
- print('Customer name:', new_customer)
- print('Today\'s date:', date)
- print()
- print_menu()
- '''
- new_item1 = construct_item()
- new_item2 = construct_item()
- print('Item 1')
- item_name1 = input('Enter the item name:\n')
- item_price1 = float(input('Enter the item price:\n'))
- item_quantity1 = int(input('Enter the item quantity:\n'))
- new_item1 = new_item1._replace(item_name = item_name1, item_price = item_price1, item_quantity = item_quantity1)
- print()
- print('Item 2')
- item_name2 = input('Enter the item name:\n')
- item_price2 = float(input('Enter the item price:\n'))
- item_quantity2 = int(input('Enter the item quantity:\n'))
- new_item2 = new_item1._replace(item_name = item_name2, item_price = item_price2, item_quantity = item_quantity2)
- print_item_cost(new_item1,new_item2)
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement