擅长:python、mysql、java
<p>您可以使用字典来存储名称和分数,这会将这两位相关数据保存在一起。使用内置的<code>sorted</code>函数首先获得最高分数,比较前两个分数以检查是否有抽屉。你知道吗</p>
<pre><code>from random import randint
l = []
def addTeam(name):
l.append(
{"name": name, "score": randint(0, 51)}
)
def sortScores():
return sorted(l, key=lambda t: t["score"], reverse=True)
def isDraw():
if l[0]["score"] == l[1]["score"]:
return True
return False
if __name__ == '__main__':
addTeam("Team1")
addTeam("Team2")
addTeam("Team3")
l = sortScores()
if isDraw():
winner = "nobody"
else:
winner = l[0]["name"]
print("The highest score is {} by: {}".format(l[0]["score"], winner))
</code></pre>
<p>尽量避免进行<code>*</code>导入,因为这可能会导致冲突。你知道吗</p>