-
Notifications
You must be signed in to change notification settings - Fork 0
/
q4.py
53 lines (31 loc) · 809 Bytes
/
q4.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#Q4 Labfinalpractice
ns = {}
totalscore = 0
while True:
inp = input("Input: ")
if inp == "done" and totalscore == 0:
print("No players")
if inp == "done":
break
name,score = inp.split()
if name not in ns:
if score.isnumeric():
score = int(score)
totalscore += score
ns[name] = score
else:
print("Invalid input")
else:
print("Duplicated player")
if totalscore != 0:
sorted_score = sorted(ns.values(),reverse =True)
average = totalscore/len(sorted_score)
for i in sorted_score:
for k,v in ns.items():
if i == v:
if i == sorted_score[0]:
print("%s\t%d\tGold"%(k,v))
elif i > average:
print("%s\t%d\tSilver"%(k,v))
else:
print("%s\t%d"%(k,v))