#๐Ÿ”’ shopping cart program error

22 messages ยท Page 1 of 1 (latest)

hushed reef
#

displays the price twice for some reason

prices = []
total = 0

while True:
    food = input("enter a food item (q to quit)  : ")
    if food.lower() == "q":
        break
    else:
        price = float(input(f"please enter the price of {food} : "))
        foods.append(food)
        prices.append(price)

print("-------- YOUR CART --------")
for food in foods:
 print(food,end=" ")

for price in prices:
 total = total + price

 print(f"your total is {total}DHS")```
covert hingeBOT
#

@hushed reef

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

hushed reef
#

x and y were the inputs for food

#

the total should be 6.98

#

but for some reason its also displaying the price of my first input

forest frigate
#

oh

#

indentation lmao

#

@hushed reef

#

for your print statement at the end

hushed reef
#

yea

forest frigate
#

its inside the for loop

hushed reef
#

oh

forest frigate
#

ya

#

so just push it out

#

no indentation

#

then test it

hushed reef
#

yeah it works thanks

forest frigate
#

all good

hushed reef
#

!close

covert hingeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.