Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- cats =["Books","Electronics","Clothing"]
- def displaymenu(cats):
- os.system('cls')
- print('Select a category below\n')
- for i in range(len(cats)):
- print('{0:2d} - {1:15s}' .format(i+1, cats[i]))
- print(' d - View current cart')
- print(' c - Checkout')
- sel = input('')
- if sel not in ('1, 2, 3, d, c'):
- print('Invalid selection, please try again')
- return sel to displaycategory()
- def displaycategory(catList):
- os.system('cls')
- for i in range(len(catList)):
- print('{0:2d} - {1:20s} {2:8.2f}' .format(i+1, catList[i][0], catList[i][1]))
- print(' d - View current cart')
- print(' x - Return to category menu')
- sel = input('')
- if sel not in ('1', '2', '3', 'd', 'x'):
- print('Invalid selection, please try again')
- return sel
- def append(sel, catList, cartList):
- sel = int(sel)
- for i in range(len(catList)):
- if i+1 == sel:
- cartList.append(catList[i])
- return cartList
- books = [['Origin',19.95],
- ['Grant' ,24.50],
- ['Prarie Fires',18.95]]
- electronics = [['HP laptop' ,429.00],
- ['Eyephone' ,790.00],
- ['Bose 20 speakers',220.00]]
- clothing = [['T-shirt' ,9.50],
- ['Shoes' ,45.00],
- ['Pants' ,24.00]]
- cart = [] # Empty cart to start
- cats =["Books","Electronics","Clothing"] # Tuple for category menu
- valid = True
- ### Defined this sentry to start and keep the program running until valid is defined as 'False' when you might display the summary of all carts.
- while valid:
- selection = displaymenu(cats)
- while selection == '1':
- option = displaycategory(books)
- if option == 'd':
- print(cart)
- input('Hit enter to continue')
- elif option == 'x':
- break
- else:
- cart = append(option, books, cart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement