Advertisement
Guest User

Untitled

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