"Building a Silent Auction Program in Python: A Step-by-Step Guide"

Arunmathavan KArunmathavan K
1 min read

First, import the os module to interact with the operating system, allows to clearing the terminal screen. So the bid amount isn't visible to others.

  •   import os
      a=input("***Welcome to the Silent Auction Program***")
    

The winner function is a crucial component of this program. It identifies the participant with the highest bid and announces the winner. This function takes one parameter 'bids' , which stores the bid values in a dictionary.

  •   def winner(bids):  #{arun:100,maddy:50,tamil:200}
          win=""
          max=0
          for i in bids: #i=arun
              bid_amount=bids[i]  #bid_amount=100
              if bid_amount>max:
                 max=bid_amount
                 win=i
         print(f"The winner is {win} with a bid of {max}")
    

This segment of the code handles the main interaction with the users, allowing multiple participants to place their bids in the silent auction. The loop continues until there are no more bidders, and then it determines the winner using the winner function.

  •   bidding={}
      try_again=False
      while not try_again:
          name=input("What is your name?: ")
          price=int(input("What is your bid?: "))
          bidding[name]=price
          again=input("Are there any other bidders? Type 'Yes' or 'No'? ").lower()
          if again=='no':
              try_again=True
              winner(bidding)
          elif again=='yes':
              os.system('cls')
    
0
Subscribe to my newsletter

Read articles from Arunmathavan K directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Arunmathavan K
Arunmathavan K