Python shopping cart program 🛒

แชร์
ฝัง
  • เผยแพร่เมื่อ 2 พ.ย. 2024

ความคิดเห็น • 85

  • @BroCodez
    @BroCodez  2 ปีที่แล้ว +43

    # 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}")

    • @SemuaTentangIkanIlham
      @SemuaTentangIkanIlham 2 ปีที่แล้ว +3

      Thanks friend .

    • @deedee9713
      @deedee9713 ปีที่แล้ว

      How do u add quantity?

    • @yuenlin2-142
      @yuenlin2-142 4 หลายเดือนก่อน

      Can you explain how we could allow the user to remove foods from their cart?😢

    • @TeckTales
      @TeckTales 23 วันที่ผ่านมา

      @@yuenlin2-142 instead of append use remove inside your if statement

  • @apathy251
    @apathy251 ปีที่แล้ว +4

    BROOO you are the best i just started learning pyhton and i couldnt get shit how the teacher explained stuff than i started to watch your vidyia and holy shit you explain it so well and easy to understand.

  • @脱不完的头发
    @脱不完的头发 8 หลายเดือนก่อน +2

    通俗易懂有逻辑!谢谢大佬!

  • @mashapetrovka430
    @mashapetrovka430 2 หลายเดือนก่อน +4

    I wanted it to show the name and price for each line so I did this instead
    # shopping cart program
    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, price in zip(foods, prices):
    print(food, f" {price}")
    total += price
    print(f"Your total is: ${total}")

  • @PonderP378
    @PonderP378 5 หลายเดือนก่อน +1

    Napaka simple ng explanation at madaling maintindihan. Salamat!

  • @skyisthelimpet
    @skyisthelimpet 2 ปีที่แล้ว +7

    Nice exercise for beginners, great work

  • @r2id_yt
    @r2id_yt 10 หลายเดือนก่อน +2

    Thank you my friend

  • @oriantiktok
    @oriantiktok 18 วันที่ผ่านมา

    WOWWWW amazing

  • @tara2337
    @tara2337 8 หลายเดือนก่อน

    I had so much fun with my shopping cart list program😁

  • @user-ze5vx6vf3n
    @user-ze5vx6vf3n 5 หลายเดือนก่อน +1

    the best tutorial that i finded

  • @nadyashaymardanova6000
    @nadyashaymardanova6000 ปีที่แล้ว +2

    Очень интересно

  • @kristijanlazarev
    @kristijanlazarev 8 หลายเดือนก่อน

    awesome

  • @gaddafisuleiman8882
    @gaddafisuleiman8882 2 ปีที่แล้ว +4

    Finally!
    You're awesome, Bro!

  • @michaelsantiago5737
    @michaelsantiago5737 2 ปีที่แล้ว +1

    More exercise please

  • @gamePlays9699
    @gamePlays9699 ปีที่แล้ว +1

    GREAT!

  • @parkashvyas5252
    @parkashvyas5252 ปีที่แล้ว

    Thank you so much.

  • @sakshamkarna9041
    @sakshamkarna9041 ปีที่แล้ว

    cool

  • @nicolewynne4781
    @nicolewynne4781 2 ปีที่แล้ว +9

    Please could you do PHP beginner full course? Your videos are like an oasis in the desert for people like us who have financial struggles. Thanks a million BRO!!!

    • @b1.7.3
      @b1.7.3 2 ปีที่แล้ว

      PHP is not really worth learning if you dont know it already, imo Express.js is way better to learn.

    • @noliyeb
      @noliyeb ปีที่แล้ว

      @@b1.7.3why is it not worth learning?

    • @VAIBHAVMALHOTRA19
      @VAIBHAVMALHOTRA19 6 หลายเดือนก่อน

      Don't listen to that person who said php isn't worth it. It is still worth it and I know people who got employed to work on the php.

  • @GeniusBro-qw8no
    @GeniusBro-qw8no 8 หลายเดือนก่อน +1

    Wrote this before watching video
    item = []
    prices= []
    print (f"Hello this is a shopping list")
    print ("if you want to quit press q")
    while True:
    f = (input(f"what would you Like to add:"))
    if f == ("q"):
    break
    else:
    item.append(f)
    while True:
    try:
    p = (int(input("what is the price of the item:$")))
    prices.append(p)
    break
    except ValueError:
    print ('please input a proper integer!')
    items = len(item)
    #print(f"total items: {item}")
    #print(f"total prices: {prices}")
    for item, price in zip(item, prices):
    print(f"- {item}: ${price}")
    print(f"total number of items:{items}")
    print(f"Price of all items: {sum(prices)}")

  • @prizepig
    @prizepig 2 ปีที่แล้ว

    Thanks for the lessons

  • @КириллБашков-ь9ж
    @КириллБашков-ь9ж 2 ปีที่แล้ว

    good work! Let's try write this program on C# )

  • @tennybabcock5146
    @tennybabcock5146 4 หลายเดือนก่อน

    i think a line of code where you can only enter string for items and float for price would be good

  • @22AT1A04CSKNATIQAHMED
    @22AT1A04CSKNATIQAHMED ปีที่แล้ว

    shopping cart program
    foods=[]
    prices=[]
    total=0
    while total>=0:
    food=input("Enter the item (q to quit): ")
    if (food=="Q")or(food=="q"):
    break
    else:
    price=float(input(f"The price of the item is $"))
    foods.append(food)
    prices.append(price)
    print("******Your items are******")
    for food in foods:
    print(food)
    for price in prices:
    total+=price
    print(f"your total is {total}")

  • @mwaijames313
    @mwaijames313 ปีที่แล้ว +5

    Surprisingly, I am getting an " unsupported operand type(s) for +: int and list" error. Here is my code
    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}: Kshs "))
    foods.append(food)
    prices.append(prices)
    print ("-----Your Cart -----")
    for food in foods:
    print (food, end= ' ')
    for price in prices:
    total += price
    print(f"Your total is Kshs{total}")
    What could be wrong here?

    • @mwaijames313
      @mwaijames313 ปีที่แล้ว +5

      Silly me. 🤣🤣🤣. I had written prices.append(prices) rather than prices.append(price).

    • @BinaryBites248
      @BinaryBites248 ปีที่แล้ว

      in prices.append(prices) you had put prices with a s

    • @jennifersilves4195
      @jennifersilves4195 11 หลายเดือนก่อน

      It's always like that.
      Glad you found the bug.

  • @22AT1A04CSKNATIQAHMED
    @22AT1A04CSKNATIQAHMED ปีที่แล้ว

    digital clock
    import time
    p=input("specify whether ypo are entering time in hours or minutes or seconds:")
    t=int(input("Enter time:"))
    if p == "hours":
    t=t*60*60
    elif p=="minutes":
    t*=60
    else:
    t=t
    for x in range(t,0,-1):
    sec=x%60
    min=int(x/60)%60
    hour=int(x/3600)%60
    print(f"{hour:02}:{min:02}:{sec:02}")
    time.sleep(1)
    print("Time is up!")

  • @eyalsilbershtein5765
    @eyalsilbershtein5765 2 ปีที่แล้ว +3

    That exercise was great! Can you do some more advanced coding Technics?

    • @CodinginAndroid
      @CodinginAndroid 11 หลายเดือนก่อน +2

      foods = []
      prices = []
      total = 0
      while True:
      food = input("Enter food name or (q to quit): ")
      if food.lower() == "q":
      break
      else:
      price = float(input("Enter price of food: $"))

      foods.append(food)
      prices.append(price)
      print("
      Items Purchased:")
      for food, price in zip(foods, prices):
      print(f"{food}: ${price:.2f}")
      total = sum(prices)
      print("
      Total: ${:.2f}".format(total))

  • @bashar8765
    @bashar8765 2 ปีที่แล้ว

    Really like those, keel them going buddy!

  • @damioni5064
    @damioni5064 6 หลายเดือนก่อน +1

    instead of print() can i use print("
    ")

  • @adilivni8688
    @adilivni8688 ปีที่แล้ว

    You should give flow to the price +=

  • @FactlessFact-ByRaji
    @FactlessFact-ByRaji 9 หลายเดือนก่อน

    can you come up with a program or project connecting python with any database like mysql ...

  • @timecop1983Two
    @timecop1983Two ปีที่แล้ว

    Don't stop bro!!! Greate videos

  • @ManideepGampa
    @ManideepGampa 2 ปีที่แล้ว +1

    Great work bro❤️❤️❤️

  • @techwithdavid
    @techwithdavid 2 ปีที่แล้ว

    Nice one 👍

  • @viktorbihar8599
    @viktorbihar8599 9 หลายเดือนก่อน

    Number 15: Burger King Foot Lettuce. bro's voice reminds me of this meme, lol.

  • @oxygen1533
    @oxygen1533 2 ปีที่แล้ว +2

    broooo, please tell us how to make money as beginner programmer

  • @ricodexr
    @ricodexr 2 ปีที่แล้ว

    🛒

  • @celestepozzi9204
    @celestepozzi9204 ปีที่แล้ว

    youre so smart, i cant figure out the foods.append(food) i cant fix it, it means my knowledge in python is still off

    • @anonymousx_x3842
      @anonymousx_x3842 ปีที่แล้ว

      i was stuck at the same point as you but look at the name of empty list for "foods" we declared at starting. then look at the "food" variable we use to get the input. now look at the append(). the error is because of the wrong variable name we are giving.

  • @space7nstuff94
    @space7nstuff94 ปีที่แล้ว +1

    What's the purpose of the f in the beginning on the string?

  • @BelleMosa
    @BelleMosa 8 หลายเดือนก่อน

    Can you make a video with a coffe shop?

  • @nalanihamby3710
    @nalanihamby3710 ปีที่แล้ว +15

    I’m so confused, I’ve got everything typed exactly as it is on the video but when I get to the price it throws an error and tells me ‘str’ object has no attribute ‘append’ why clue what I am doing wrong?

    • @sarahmadrid6606
      @sarahmadrid6606 ปีที่แล้ว +6

      print needs to be changed to a float: total += float(price)

    • @adilivni8688
      @adilivni8688 ปีที่แล้ว +1

      And he did not tell us😤

    • @synxedits25
      @synxedits25 ปีที่แล้ว

      @@adilivni8688 he did, actually 3:11

    • @Pawfessor1
      @Pawfessor1 3 หลายเดือนก่อน

      skill issue

    • @Emmanuel-l7y1h
      @Emmanuel-l7y1h 3 หลายเดือนก่อน

      Same

  • @adamesmail
    @adamesmail 8 หลายเดือนก่อน

    hello

  • @harrybean3244
    @harrybean3244 2 ปีที่แล้ว

    NOW THAT IS GIGA :) I rate it giga/10

  • @setok5231
    @setok5231 2 ปีที่แล้ว

    Can you make a video how to create round button in java pls😢

  • @corexx
    @corexx 2 ปีที่แล้ว

    You are the best bro code, i hope you see this!

  • @ronitsworld9388
    @ronitsworld9388 หลายเดือนก่อน

    his typing speed fr 💀💀💀

  • @CodinginAndroid
    @CodinginAndroid 11 หลายเดือนก่อน

    foods = []
    prices = []
    total = 0
    while True:
    food = input("Enter food name or (q to quit): ")
    if food.lower() == "q":
    break
    else:
    price = float(input("Enter price of food: $"))

    foods.append(food)
    prices.append(price)
    print("
    Items Purchased:")
    for food, price in zip(foods, prices):
    print(f"{food}: ${price:.2f}")
    total = sum(prices)
    print("
    Total: ${:.2f}".format(total))

  • @adilivni8688
    @adilivni8688 ปีที่แล้ว

    You forgot to put flow in the price.

  • @TermiTech2011
    @TermiTech2011 2 ปีที่แล้ว

    How you enjoy the Dracula theme in pycharn?

  • @calowed
    @calowed ปีที่แล้ว +1

    is there a way to add taxes? like a percentage that adds onto the total.

  • @aissaboukrikeb1591
    @aissaboukrikeb1591 7 หลายเดือนก่อน

    what if the user enter letter not number in price? HOW WE CAN FIXIT

  • @touchedbygod235
    @touchedbygod235 8 หลายเดือนก่อน

    I got everything in 4:45 but it is saying error on line 12 did you mean price

  • @DogasNetwork
    @DogasNetwork ปีที่แล้ว

    @Bro Code which IDE are you using? 🙂

  • @DesiredFactsDaily
    @DesiredFactsDaily ปีที่แล้ว

    Bruhhhhhhhhhhhhhhhhhhhhhh.....Im here

  • @Beeposky
    @Beeposky ปีที่แล้ว

    how do you declare a list? ive atempted to make something similar to this but my lists are getting the undeclared error

  • @ratulmitra347
    @ratulmitra347 6 หลายเดือนก่อน

    price=float(input(f"enter the price of a {food}: ₹''))
    This line is wrong? I don't understand....
    SyntaxError: unterminated string literal (detected at line 9)
    This is showing

  • @Not_AltAccount
    @Not_AltAccount 10 หลายเดือนก่อน

    What was the program to code Python again?

    • @xMythric
      @xMythric 8 หลายเดือนก่อน

      There are many types of programs based on your device. For example you could use the official python app on a computer which is the one he uses or i use pyto because i code python on an ipad

  • @keikoo3282
    @keikoo3282 ปีที่แล้ว

    And pay in Bitcoin ?

  • @noahschmidt7996
    @noahschmidt7996 8 หลายเดือนก่อน

    Why does my list say q q q?

  • @RaytonSatkek
    @RaytonSatkek ปีที่แล้ว

    class Product:
    def __init__(self, product_id, product_name, unit_price):
    self.product_id = product_id
    self.product_name = product_name
    self.unit_price = unit_price
    def display_product_details(self):
    print("Product ID:", self.product_id)
    print("Product Name:", self.product_name)
    print("Unit Price:", self.unit_price)
    # Example usage:
    product1 = Product(1, "Widget", 10.99)
    product1.display_product_details()
    Tried running on PC and not working, please help

  • @aFirmae
    @aFirmae ปีที่แล้ว +2

    Ok, so I tried making this output look better, but failed at displaying the cart with proper alignment, can anyone help?
    I think this line of the code needs to be modified, print(f"{i}. {food.capitalize()} x {quantity:

    • @aFirmae
      @aFirmae ปีที่แล้ว

      I want the "YOUR CART" to look like:
      ---------------- YOUR CART -------------
      1. Pizza x 4 $23.96
      2. Hamburgers x 3 $10.5
      3. Hotdogs x 2 $ 3.0
      --------------------------------------------------

    • @aFirmae
      @aFirmae ปีที่แล้ว

      Sample Output:
      Enter your food products. Press Enter to quit.
      1. pizza
      Price of pizza: 5.99
      Number of pizza: 4
      2. hamburgers
      Price of hamburgers: 3.50
      Number of hamburgers: 3
      3. hotdogs
      Price of hotdogs: 1.50
      Number of hotdogs: 2
      4.
      --------- YOUR CART -----------
      1. Pizza x 4 $23.96
      2. Hamburgers x 3 $10.5
      3. Hotdogs x 2 $3.0
      ----------------------------------------
      Your total is: $37.46

  • @DannLopez-l4n
    @DannLopez-l4n 10 หลายเดือนก่อน

    I MADE THIS CODE, THIS IS BETTER, IT MAKES IT VERTICAL LIKE A RECIPT 👇
    #Declare variables
    foods = []
    prices = []
    total = 0.0
    while True:
    food = input("Enter a food to buy: (press q to quit): ")
    if food.lower() == "q":
    break
    else:
    price = float(input(f"Enter the price of {food}: $"))
    foods.append(food) #This will put the values of food to foods
    prices.append(price)
    print("

    -------YOUR CART-------")
    j = 0
    for x in foods:
    print(f"{x: