Advertisement
Guest User

Untitled

a guest
Nov 11th, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. #Maggie_Potts_A8.py
  2. #Assignment 8 Amazin.com Shopping 2.0
  3.  
  4. #wrap in while loop for more carts
  5.  
  6. def transaction():
  7.  
  8. cats =["Books","Electronics","Clothing"]
  9. carts = [[0,0,0]]
  10. curcart = 0
  11. cost = [0,0,0]
  12.  
  13. books = [19.95,24.50,18.95]
  14. electronics = [429,790,220]
  15. clothing = [9.50,45,24]
  16.  
  17. menu = ("""
  18. 1 - Books
  19. 2 - Electronics
  20. 3 - Clothing
  21. 4 - Checkout
  22.  
  23. Select one of the categories or checkout (1-4):
  24. """)
  25.  
  26. while True:
  27.  
  28. print(menu)
  29. selection = int(input())
  30.  
  31. if selection == 1:
  32. print("1. Origin, $19.95")
  33. print("2. Grant, $24.50")
  34. print("3. Prairie Fries, $18.95")
  35. print("4. No Selection") #can't make 'x' because input is integer
  36. print("\n Select a title or select 4 for no selection (1-4): ")
  37.  
  38. sel2 = int(input())
  39.  
  40. if sel2 >= 1 and sel2 <= 3:
  41. carts[curcart][0] += 1
  42. cost[0] += books[sel2-1]
  43.  
  44.  
  45. elif selection == 2:
  46. print("1. Hp laptop, $429.50")
  47. print("2. EyePhone, $790.00")
  48. print("3. Bose 20 speakers, $220.00")
  49. print("4. No Selection")
  50. print("\n Select an electronic or select 4 for no selection (1-4): ")
  51.  
  52. sel2 = int(input())
  53.  
  54. if sel2 >=1 and sel2 <= 3:
  55. carts[curcart][1] += 1
  56. cost[1] += electronics[sel2-1]
  57.  
  58. elif selection == 3:
  59. print("1. T-shirt, $9.50")
  60. print("2. Shoes, $45.00")
  61. print("3. Pants, $24.00")
  62. print("4. No Selection")
  63. print("\n Select a clothing item or select 4 for no selection (1-4): ")
  64.  
  65. sel2 = int(input())
  66.  
  67. if sel2 >=1 and sel2 <=3:
  68. carts[curcart][2] += 1
  69. cost[2] += clothing[sel2-1]
  70.  
  71. if selection == 4:
  72. more = "" #word of advice - do not declare variables until you are at the layer you need them
  73. print("Checking Out...\n")
  74. print("\nCart:\n")
  75. print("%-20s %-20s %-20s"%("--------","---------------","-------------"))
  76. print("%-20s %-20s %-20s"%("Category","Number of items","Cost of items"))
  77. print("%-20s %-20s %-20s"%("--------","---------------","-------------"))
  78.  
  79. for i in range(len(carts[curcart])):
  80. if(carts[curcart][i]!=0):
  81. print("%-27s %-17d $%.1f"%(cats[i],carts[curcart][i],cost[i]))
  82.  
  83. print("%-27s %-17d $%.1f"%("Total",sum(carts[curcart]),sum(cost)))
  84.  
  85. while more.upper() not in "YN" or more == "":
  86. print("\n")
  87. more = input("Do you have more shopping to do? (Y or N)")
  88.  
  89. if more.upper == "Y":
  90. carts.append([0,0,0])
  91. curcart += 1
  92. transaction()
  93.  
  94. else:
  95. break
  96.  
  97.  
  98. print("\nTotal Carts:", curcart)
  99. print("%-20s %-20s %-20s"%("--------","---------------","-------------"))
  100. print("%-20s %-20s %-20s"%("Category","Number of items","Cost of items"))
  101. print("%-20s %-20s %-20s"%("--------","---------------","-------------"))
  102.  
  103. for c in carts:
  104. for i in range(len(c)):
  105. if(c[i]!=0):
  106. print("%-27s %-17d $%.1f"%(cats[i],c[i],cost[i]))
  107.  
  108. print("%-27s %-17d $%.1f"%("Total",sum(carts[curcart]),sum(cost)))
  109.  
  110. transaction()
  111.  
  112. input("\n\nHit Enter to end program")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement