+ 1

How do u calculate average mark for a maximum of 5 entries using a dictionary

student={} for i in range(5): name=input() mark=int(input) student.update({'name':name,'mark':mark}) print(student)

13th Mar 2021, 9:09 PM
simbarashe
6 Respuestas
+ 1
well you loop over the dictionary keys, add the marks value and divide it by 5. i. e. sum=0 for i in student: sum+=student[i] print(sum/5) And it is "mark=int(input())"
13th Mar 2021, 9:13 PM
Abhay
Abhay - avatar
+ 1
simbarashe Is this 5 students with 1 mark each? Which is what the code you have posted does. If so you can just use the sum() function on a list of the values from the dict, divided by the length of the dictionary. average_mark = sum(list(student.values())) / len(student) If this is not the correct structure for your dictionary then please describe further.
13th Mar 2021, 10:42 PM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Would something like this help students = { "Bob" : 41, "Jak" : 62, "Amy" : 98, } total = 0 for i in students: total += students[i] average = total / len(students) print(average)
14th Mar 2021, 12:27 AM
Rik Wittkopp
Rik Wittkopp - avatar
0
Abhay i have done wat u suggested but still not working
13th Mar 2021, 9:25 PM
simbarashe
0
simbarashe can you show me your code?
13th Mar 2021, 10:11 PM
Abhay
Abhay - avatar
0
student_1 = input() ... student_5 = input() sum = student_1 + ... + student_5 avg = sum/5 print(avg) You can attribute a number for each student. Python also understand Ab>Ac = True. You can put them in order too.
13th Mar 2021, 11:45 PM
▲TopGun ▲
▲TopGun ▲ - avatar