Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

Python shopping cart program 🛒

169.4K views on YouTube

#python #tutorial #course

# Shopping cart exercise

foods = []
prices = []
total = 0

while True:
food = input(“Enter a food to buy (q to quit): “)
if food.lower() == “q”:
break
else:
price = float(input(f”Enter the price of a {food}: $”))
foods.append(food)
prices.append(price)

print(“—– YOUR CART —–“)

for food in foods:
print(food, end=” “)

for price in prices:
total += price

print()
print(f”Your total is: ${total}”)