Python Forum
Shopping cart program
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Shopping cart program
#5
(Jun-26-2022, 11:58 PM)BashBedlam Wrote: This whole thing would be significantly easier if you could us a dictionary for your cart. The item name would be the key and the price would be the value. If you've been taught about dictionaries, I would start off with something like this:
cart = {} 
print("Welcome to the Shopping Cart Program!")

while True:
	print()
	print ("Please type in one of these")
	print ("1. Add item ")
	print ("2. View cart ")
	print ("3. Remove Item ")
	print ("4 compute total")
	print ("5 exit program")
 
	select = int(input(" Type in a number to go on "))

	if select == 1:
		item = input(" What would you like to add?  ")
		price = float(input(" type in the price "))
		cart [item] = price
		print(f"'{item}' has been added to your cart.")
		print(f" The price is ${price}")

	if select == 2:
		print("This is what is in your shopping cart")
		for item in cart:
			print(f"  {item} - ${cart [item]}")

	if select == 3:
		takeout = input(" Type in what you would like to remove?  ")
		cart.pop(takeout)

	if select == 4:
		total = 0
		for item in cart:
			total += cart [item]
		print(f" ${total}")

	if select == 5:
		print ("comeback soon.")
		break
yeah he hasn't the whole class is pretty clueless and stuck
Reply


Messages In This Thread
Shopping cart program - by Tofuboi03 - Jun-26-2022, 06:12 AM
RE: Shopping cart program - by rob101 - Jun-26-2022, 07:36 AM
RE: Shopping cart program - by rob101 - Jun-26-2022, 11:29 PM
RE: Shopping cart program - by Tofuboi03 - Jun-27-2022, 03:50 AM
RE: Shopping cart program - by BashBedlam - Jun-26-2022, 11:58 PM
RE: Shopping cart program - by Tofuboi03 - Jun-27-2022, 03:43 AM
RE: Shopping cart program - by rob101 - Jun-27-2022, 07:53 AM
RE: Shopping cart program - by shoesinquiry - Sep-07-2023, 09:41 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  project shopping cart pkmnmewtwo 1 3,382 May-03-2020, 10:46 PM
Last Post: pkmnmewtwo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020