I am new to Python. I am learning through this 100 days video tutorial from Udemy. However surprisingly same code worked for the tutor on video but not for me. After going through current posts with similar error I couldn't figure out the solution and decided to post my question. I have checked in Thonny debugger an code- bid_amnt = bidding_record[bidder] is where value comes with the coma at the end. I have tried converting it to integer by int(bidding_record[bidder]) also but it didn't work. Please tell me how to correct.
#Code snippet
def find_highest_bidder(bidding_record):
#bidding_record = {Angela:123, James:321} examlpe of dictionary prepared
highest_bid = 0
winner = ""
for bidder in bidding_record:
bid_amnt = bidding_record[bidder]
if bid_amnt > highest_bid:
highest_bid = bid_amnt
winner = bidder
print(f"Winner of this bid is {winner} with ${highest_bid}")
#Declaring variable for loop and empty dictionary
bid_on = True
while bid_on == True:
#Taking user Inputs
name = input("Please enter your name: \n")
bid_value = int(input("please enter your bid amount: $"))
other_users = input("are there other users who want to bid type yes/no: \n").lower()
bid_dict[name] = bid_value,
#Calling function by passing dictionary in argument
find_highest_bidder(bid_dict)
#Calling clear function from replit if there are no more users
if other_users == "no":
bid_on = False
else:
clear()
CodePudding user response:
I see what happened. In the line bid_dict[name] = bid_value,
you are defining bid_dict[name]
to be a tuple since bid_value
has a ,
after it.
In python, whenever you put a comma after a variable like this, it expects it to be a tuple and converts it to that datatype.
Then in the line if bid_amnt > highest_bid:
it is trying to compare bid_amnt
which is the tuple
you defined above with bid_value,
to the int
you defined as highest_bid = 0
Remove that comma and it should work.