【问题描述】已知有三位候选人(“Lily”,"John","Rose")参加班长竞选,10位学生参与投票,统计每位候选人的得票数,并按照从高到低输出。
【输入形式】"Input the name of candidate:”
can = ("Lily", "John", "Rose")
i = 0
d = {}
while i < 3:
c = input("Input the name of candidate:")
if c not in can:
print("Error!")
else:
d[c] = d.get(c, 0) + 1
i += 1
for k, v in sorted(d.items(), key=lambda x: x[1], reverse=True):
print(k, v)