【发布时间】:2022-11-16 19:22:39
【问题描述】:
有人可以帮我弄这个吗?我究竟做错了什么?我查看了Angela Yu博士的解决方案。她以不同的方式解决了这个问题,但我无法理解我在哪里犯了错误。
该程序应打印出价最高者的姓名和出价。但是,当我运行此代码时,控制台会打印出价和最后输入的名称。
from replit import clear
#HINT: You can call clear() to clear the output in the console.
from art import logo
print (logo)
game_end = False
bids = {}
while not game_end:
name = input("What is your name?\n")
bid = int(input("How much are you bidding? $"))
bids[name] = bid
game = input("Are there any other bidders. y or n\n").lower()
if game == "n":
game_end = True
else:
clear()
highest_bid = 0
for bidder in bids:
if bid > highest_bid:
highest_bid = bid
winner = bidder
print(f"The winner is {winner} with a bid of ${highest_bid}")
【问题讨论】:
标签: python dictionary replit