Today I started learning about a new data type: dictionaries. At first I thought that the fuctions would be fairly similar such as .append() .remove() and other various fuctions, but, a quick look at Python's documentations and some videos told me wrong.
After getting the hang of calling, wiping and adding stuff to a dictionary, I went to work on nested lists and dictionaries. While I can see how they would be quite useful with larger and more complext amounts of data, for smaller examples they are not really needed and since I didn't have any ideas for what complex data inputs I could make them hold, I came up with some random and to be honest, very silly, examples.
For today's project, I did a Secret Auction Program. After doing yesterday's project I thought that today's one will also be quite difficult or harder but it turns out that it was quite easy. The way it works is that the user enters their name and bid, which will then be stored in a dictionary. It then clears the screen, print("\n" * 20), and then moves on to the next bidder. Once all of the people have bid then it works out the largest value in the dictionary and prints out the key and value of the person that won the bid.
from art import logo
print(logo)
bidding = True
auction_dictionary = {}
while bidding != False:
user_name = str(input("Please enter your name: "))
user_bid = int(input("Please enter your bid: $ "))
user_continue = str(input("Type 'yes' if there are more people to bid, otherwise type 'no': "))
auction_dictionary[user_name] = user_bid
if user_continue == "yes":
print("\n" * 25)
bidding = True
else:
bidding = False
print("\n" * 25)
highest_bid = 0
winner = 0
for key in auction_dictionary:
if auction_dictionary[key] > highest_bid:
highest_bid = auction_dictionary[key]
winner = key
print("The highest bidder is", winner, "with a bid of", highest_bid)
Top comments (0)