Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Maggie_Potts_A8.py
- #Assignment 8 Amazin.com Shopping 2.0
- #wrap in while loop for more carts
- def transaction():
- cats =["Books","Electronics","Clothing"]
- carts = [[0,0,0]]
- curcart = 0
- cost = [0,0,0]
- more = "Y"
- books = [19.95,24.50,18.95]
- electronics = [429,790,220]
- clothing = [9.50,45,24]
- menu = ("""
- 1 - Books
- 2 - Electronics
- 3 - Clothing
- 4 - Checkout
- Select one of the categories or checkout (1-4):
- """)
- while True:
- print(menu)
- selection = int(input())
- if selection == 1:
- print("1. Origin, $19.95")
- print("2. Grant, $24.50")
- print("3. Prairie Fries, $18.95")
- print("4. No Selection") #can't make 'x' because input is integer
- print("\n Select a title or select 4 for no selection (1-4): ")
- sel2 = int(input())
- if sel2 >= 1 and sel2 <= 3:
- carts[curcart][0] += 1
- cost[0] += books[sel2-1]
- elif selection == 2:
- print("1. Hp laptop, $429.50")
- print("2. EyePhone, $790.00")
- print("3. Bose 20 speakers, $220.00")
- print("4. No Selection")
- print("\n Select an electronic or select 4 for no selection (1-4): ")
- sel2 = int(input())
- if sel2 >=1 and sel2 <= 3:
- carts[curcart][1] += 1
- cost[1] += electronics[sel2-1]
- elif selection == 3:
- print("1. T-shirt, $9.50")
- print("2. Shoes, $45.00")
- print("3. Pants, $24.00")
- print("4. No Selection")
- print("\n Select a clothing item or select 4 for no selection (1-4): ")
- sel2 = int(input())
- if sel2 >=1 and sel2 <=3:
- carts[curcart][2] += 1
- cost[2] += clothing[sel2-1]
- if selection == 4:
- print("Checking Out...")
- break
- print("\nCart:\n")
- print("%-20s %-20s %-20s"%("--------","---------------","-------------"))
- print("%-20s %-20s %-20s"%("Category","Number of items","Cost of items"))
- print("%-20s %-20s %-20s"%("--------","---------------","-------------"))
- for i in range(len(carts[curcart])):
- if(carts[curcart][i]!=0):
- print("%-27s %-17d $%.1f"%(cats[i],carts[curcart][i],cost[i]))
- print("%-27s %-17d $%.1f"%("Total",sum(carts[curcart]),sum(cost)))
- while more.upper() == "Y":
- print("\n")
- morecarts = input("Do you have more shopping to do? (Y or N)")
- carts.append()[0,0,0]
- curcart += 1
- if morecarts not in "Yy":
- break
- transaction()
- input("\n\nHit Enter to end program")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement