0

Average score.

I have to input the number of students (3). Then three scores for each student (I used the dictionary below). Then print the average score for one of the students. Floats are okay. Example input: 3 Sam 1 2 3 Mark 2 3 4 Josh 4 5 6 Josh Output: 5.00 #Josh's average score. I got the following error message: "d = (a)/3 TypeError: unsupported operand type(s) for /: 'dict' and 'int'" So I need to convert everything to an integer or a string (code and link are below)? Any help greatly appreciated. x = int(input()) a = {input():[int(input()), int(input()), int(input())]} b = {input():[int(input()), int(input()), int(input())]} c = {input():[int(input()), int(input()), int(input())]} d = (a)/3 print(d) https://code.sololearn.com/cN410aMjf0uS/#py

20th Sep 2019, 9:43 PM
tristach605
tristach605 - avatar
4 ответов
+ 2
Change it to: d = sum( list(a.values())[0] )/3
20th Sep 2019, 10:06 PM
Rustem Sharipov
Rustem Sharipov - avatar
+ 2
print(sum(*a.values())/3)
21st Sep 2019, 1:08 AM
Choe
Choe - avatar
+ 1
Thanks everyone (almost there)! The following code worked (thanks to all)! Last step is to make the last line an input. As it is now, it will only print the a value (line 2). How do I add an input? I tried several options but got errors on all of them. It should be possible. Thanks in advance for any help. x = int(input()) a = {input():[int(input()), int(input()), int(input())]} b = {input():[int(input()), int(input()), int(input())]} c = {input():[int(input()), int(input()), int(input())]} print(sum(*a.values())/3) https://code.sololearn.com/cu3z7p4Op3CR/#py
21st Sep 2019, 10:36 PM
tristach605
tristach605 - avatar
0
tristach605 n = input() for k,v in {**a,**b,**c}.items(): if k==n: print(sum(v)/3)
22nd Sep 2019, 2:19 AM
Choe
Choe - avatar