Python Dictionary -- a shopping basket example

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

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

  • @ijeffking
    @ijeffking 7 ปีที่แล้ว +8

    Excellent example for practising dictionaries and understanding how to use them within a loop. Thank you very much

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

    I found your video very helpful with an interesting set of examples. Thank you very much !

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

    short and sweet code plus explanation...well done.

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

    Good example , very good color on screen . Thanks a lot .

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

    amazing example for dictionary with this video you can clearly understand the concept of this like + subscribe congratulations for your job :)

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

    Thank you very much for the wonderful explanation i struggle to understand dictonary

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

    Thank you so much..It really helped !

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

    thanks i did the program , but when choose option 1 i can not move to another option , why ?

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

    Very interesting indeed but how this be done with a class as marketshop?

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

    Thank you for sharing. This is my version of the code:
    import os
    import time
    Basket={}
    print("""
    1. Add Item
    2. Remove Item
    3. View Basket
    0. Exit
    """)
    option=int(input("Enter an Option: "))
    while option!=0:
    try:
    if option==1:
    Item=input("Enter Item: ")
    qty=int(input("Enter Quantity: "))
    if Item in Basket:
    Basket[Item]+=qty
    else:
    Basket[Item]=qty
    print("Saved")
    elif option==2:
    Item=input("Enter Item to Delete: ")
    del(Basket[Item])
    print("Deleted")
    elif option==3:
    if len(Basket)==0:
    print("Baksket is Empty.")
    else:
    for Item in Basket:
    print(Item,": ",Basket[Item])
    elif option!=0:
    print("Wrong Option Enter.")
    time.sleep(5)
    os.system("clear") # or cls
    print("""
    1. Add Item
    2. Remove Item
    3. View Basket
    0. Exit
    """)
    option=int(input("Enter Option: "))
    except Exception as e:
    print("Wrong information Enter. Try again.")
    time.sleep(5)
    os.system("clear")
    print("""
    1. Add Item
    2. Remove Item
    3. View Basket
    0. Exit
    """)
    option=int(input("Enter Option: "))
    print("Basket Closed.")

  • @mentes.a5327
    @mentes.a5327 2 ปีที่แล้ว

    Thank you so much

  • @dolfinho87
    @dolfinho87 3 ปีที่แล้ว

    Perfect!!!! Thanks!

  • @sajithjanardhanan123
    @sajithjanardhanan123 4 ปีที่แล้ว

    Could not see the programing code lines.. please incease your font size or zoom the screen

  • @5e1va
    @5e1va 3 ปีที่แล้ว

    Thank you brother

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

    Pls share the code

  • @Alex-ns1pj
    @Alex-ns1pj 5 ปีที่แล้ว

    What would I do if I wanted an option for if the user entered a string? I tried
    elif option == str:
    print('-Enter valid number-')
    it was no good

    • @cyl3611
      @cyl3611 4 ปีที่แล้ว

      Whatever the user inputs is taken as a string by pthon. Even if it is a number.
      u can print all the potions like in the video, then you can do something like this.
      else:
      print("You didnt put a valid number")

    • @realnice3672
      @realnice3672 4 ปีที่แล้ว

      option = input("give a option:")
      elif option == "str":
      print("-Enter valid number-")

    • @kanwal4805
      @kanwal4805 3 ปีที่แล้ว

      shopping_basket = {}
      print("""
      Shopping Basket Options
      ----------------------
      1: Add item
      2: Remove item
      3: view basket
      0: Exit program
      """)
      while True:
      try:
      option = int(input("Enter an option: "))
      while option != 0:
      if option == 1:
      item = input("Enter an item: ")
      if item in shopping_basket:
      print("items exists already!")
      quantity = int(input("Enter the quantity: "))
      shopping_basket[item] += quantity
      else:
      quantity = int(input("Enter the quantity: "))
      shopping_basket[item] = quantity
      elif option == 2:
      item = input("Enter an item: ")
      if item in shopping_basket:
      del (shopping_basket[item])
      else:
      print("item doesn't exist in shopping basket")
      elif option == 3:
      print(shopping_basket)
      for item in shopping_basket:
      print(item, ':', shopping_basket[item])
      elif option != 0:
      print("you didn't enter a valid number")
      option = int(input("

      Enter an option: "))
      except ValueError:
      print("please enter a valid number")

  • @arunorton
    @arunorton 4 ปีที่แล้ว

    How to add a employee class object and how to print the value using looping

    • @nathantyrell4898
      @nathantyrell4898 3 ปีที่แล้ว

      Class business:
      Def __init__(self,employee):
      self.employee = employee
      (I think you would enter a similar code with "value" in)be more precise with what you are trying to say and then you can be helped)

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

    audio is not upto scratch....

  • @avheeaziz5877
    @avheeaziz5877 4 ปีที่แล้ว

    Can't see in mobile .. plz zoom ..

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

    First