班里选班长,票数记在字典里:名字对票数。写 winner(votes),返回票最多的名字。一样多的时候,返回字典里排在前面的那个。字典里至少有一个人。
winner({"Amy": 5, "Ben": 8, "Cat": 3})→'Ben'winner({"Leo": 4, "Mia": 4})→'Leo'def winner(votes):
best_name = ""
best_count = -1
for name, count in votes.items():
# 在这里写:票比 best_count 多,就记下这个人
pass
return best_name
写好了先点「运行」试试示例,没问题再点「提交」。