tim@crunchbang:~/workspace/baidu$ cat qa.py
def getter():
try:
name = input("Player Name: ")
degree = float(input("FG%: "))
return (name, degree)
except:
return None
# collect
datas = []
while True:
data = getter()
if not data:
break
datas.append(data)
# output
result = [x[0] for x in sorted(datas, key=lambda x: x[1])[-2::-1]]
print("""
The Player of the Year is: %s
The Runner Up is: %s
""" % (result[0], result[1])
)tim@crunchbang:~/workspace/baidu$ python3 qa.py
Player Name: Stephen Curry
FG%: .451
Player Name: LeBron James
FG%: .565
Player Name: James Harden
FG%: .438
Player Name: Carmelo Anthony
FG%: .449
Player Name: Kevin Durant
FG%: .510
Player Name:
FG%:
The Player of the Year is: Kevin Durant
The Runner Up is: Stephen Curry
tim@crunchbang:~/workspace/baidu$
该程序通过用户输入收集球员名字和投篮命中率,然后进行排序,最终输出年度最佳球员和亚军。输入数据包括Stephen Curry、LeBron James、James Harden、Carmelo Anthony和Kevin Durant等球员的信息。经过计算,Kevin Durant被评为年度最佳球员,Stephen Curry为亚军。

2232

被折叠的 条评论
为什么被折叠?



