Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. import os
  2.  
  3. cats =["Books","Electronics","Clothing"]
  4.  
  5. def displaymenu(cats):
  6. os.system('cls')
  7. print('Select a category below\n')
  8. for i in range(len(cats)):
  9. print('{0:2d} - {1:15s}' .format(i+1, cats[i]))
  10. print(' d - View current cart')
  11. print(' c - Checkout')
  12.  
  13. sel = input('')
  14.  
  15. if sel not in ('1, 2, 3, d, c'):
  16. print('Invalid selection, please try again')
  17.  
  18. return sel to displaycategory()
  19.  
  20. def displaycategory(catList):
  21. os.system('cls')
  22. for i in range(len(catList)):
  23. print('{0:2d} - {1:20s} {2:8.2f}' .format(i+1, catList[i][0], catList[i][1]))
  24. print(' d - View current cart')
  25. print(' x - Return to category menu')
  26.  
  27. sel = input('')
  28.  
  29. if sel not in ('1', '2', '3', 'd', 'x'):
  30. print('Invalid selection, please try again')
  31.  
  32. return sel
  33.  
  34. def append(sel, catList, cartList):
  35.  
  36. sel = int(sel)
  37.  
  38. for i in range(len(catList)):
  39. if i+1 == sel:
  40. cartList.append(catList[i])
  41. return cartList
  42.  
  43. books = [['Origin',19.95],
  44. ['Grant' ,24.50],
  45. ['Prarie Fires',18.95]]
  46.  
  47. electronics = [['HP laptop' ,429.00],
  48. ['Eyephone' ,790.00],
  49. ['Bose 20 speakers',220.00]]
  50.  
  51. clothing = [['T-shirt' ,9.50],
  52. ['Shoes' ,45.00],
  53. ['Pants' ,24.00]]
  54.  
  55. cart = [] # Empty cart to start
  56.  
  57. cats =["Books","Electronics","Clothing"] # Tuple for category menu
  58.  
  59. valid = True
  60.  
  61. ### 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.
  62.  
  63. while valid:
  64.  
  65. selection = displaymenu(cats)
  66.  
  67. while selection == '1':
  68.  
  69. option = displaycategory(books)
  70.  
  71. if option == 'd':
  72. print(cart)
  73. input('Hit enter to continue')
  74.  
  75. elif option == 'x':
  76. break
  77.  
  78. else:
  79. cart = append(option, books, cart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement