DEV Community

dongdiri
dongdiri

Posted on • Edited on

DAY6: Python day 9

Dictionaries

  • can add item to dictionary by simply assigning value to key.
dict["key"] = "value"
Enter fullscreen mode Exit fullscreen mode
  • nesting lists and dictionaries in a dictionary and vice versa
dictionary = {
    key: [list],
    key2: {dict},
}
Enter fullscreen mode Exit fullscreen mode

End of the lesson project: Blind auction

from replit import clear
from art import logo
#HINT: You can call clear() to clear the output in the console.
print(logo)
dictionary = {}

def bidder():
  name = input("What is your name? ")
  bid = int(input("What is your bid? $"))

  dictionary[name] = bid
  ask = input("Is there anyone else to bid? yes/no ")
  if ask == "yes": 
    clear()
    bidder()
  else: 
    best_bidder = ""
    best_bid = 0
    for key in dictionary: 
      if dictionary[key] > best_bid:
        best_bidder = key
        best_bid = dictionary[key]
    print(f"The winner is {best_bidder} with a bid of ${best_bid}.")

bidder()
Enter fullscreen mode Exit fullscreen mode

Top comments (0)