-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise.py
More file actions
29 lines (25 loc) · 750 Bytes
/
exercise.py
File metadata and controls
29 lines (25 loc) · 750 Bytes
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
def getdatafromuser():
D = {}
while True:
studentId = input("Enter student id: ")
marklist = input("Enter Marks By comma-separated Value: ")
morestudents = input("Enter 'no' to quit: ")
if studentId in D:
print(studentId, "is already inserted")
else:
D[studentId] = marklist.split(",")
if morestudents.lower() == "no":
return D
studentdata = getdatafromuser()
def getavgmarks(D):
avgmarks = {}
for x in D:
l = D[x]
s = 0
for marks in l:
s += float(marks)
avgmarks[x] = s / len(l)
return avgmarks
avgm = getavgmarks(studentdata)
for x in avgm:
print("student:", x, "got avg marks as:", avgm[x])