-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq6.py
35 lines (31 loc) · 979 Bytes
/
q6.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
#Q6 Labfinalpractice
pair = {}
totalscore = 0
while True:
sid,score = input("Enter student ID and score: ").split()
if sid == "done" and score == "0":
break
if sid.isnumeric() and len(sid) == 4:
sid = int(sid)
if score.isnumeric() and 100 >= int(score) >= 0:
score = int(score)
if sid not in pair:
pair[sid] = score
totalscore += score
else:
print("The ID is already recorded!")
else:
print("Invalid score!")
else:
print("Invalid ID format!")
def ListOfStudent():
totalsd = len(pair.keys())
print("List:")
if totalsd == 0:
print("> no score is recorded!")
else:
average = totalscore / totalsd
for k,v in sorted(pair.items()):
print("%d \t %d"%(k,v))
print("There are %d student(s). The average score is %.2f points."%(totalsd,average))
ListOfStudent()