Blind Auction Tool | Python
Going Once… Going Twice… Gone! I’ve built a Blind Auction Tool for my next coding exercise. This small project could easily be implemented on a tablet or Raspberry Pi for a fundraiser or other event that is holding an auction. The Blind Auction Tool gathers bidder names and their maximum bid, storing these details in a dictionary. After each bidder has submitted their bid, the tool will announce the winner with the corresponding winning bet. You know the drill by now! Let’s dive into the code…
I start with importing the ASCII logo of a gavel, which is used as the banner image for this program, and ‘system’ from the ‘os’ module. I then create an empty dictionary called ‘auction_dictionary’ and set the variable ‘final_bid’ to the Boolean value False.
Next, I define a function called clear() which checks if name is equal to ‘nt’ (for Windows) and if so, clears the terminal via the ‘cls’ system command. After this, I defined another function called find_highest_bidder() which takes the argument ‘auction_dictionary’. Within this function call, a local variable ‘top_bid’ is set to 0 and ‘highest_bidder’ is set to an empty string.
When find_highest_bidder() is called, each bidder stored within ‘auction_dictionary’ is iterated over and the ‘bid’ variable is set to the value of the current bidder. If the value stored in ‘bid’ is greater than the value stored in ‘top_bid’, the ‘top_bid’ variable is set to the value of ‘bid’ (the first bid checked will automatically be stored in ‘top_bid’ since the value is set to 0 at the start). Additionally, the ‘highest_bidder’ variable is set to the current ‘bidder’.
After iterating through all the bidders stored in the dictionary, both ‘top_bid’ and ‘highest_bidder’ will hold their appropriate value and the print function will congratulate the highest bidder by name and confirm their bid.
Finally, while ‘final_bid’ is not set to True, the program prints the gavel logo and a welcome message. The user is then prompted for their name and top bid, which are stored in the ‘bidder’ and ‘bid’ variables respectively. Each submission is then stored in ‘auction_dictionary’ as a key/value pair.
After each submission, the user is prompted as to whether there is another bidder. If so, the program will call clear() to clear the screen for privacy and then loops back to the ready state for the next submission. If not, find_highest_bidder() is called and the winner is announced.
As always, you can view and download the source code for this project on my GitHub by clicking here. Thank you for your time!