Average score. | Sololearn: Learn to code for FREE!

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

9/20/2019 9:43:14 PM

tristach605

5 Answers

New Answer

+2

Change it to: d = sum( list(a.values())[0] )/3

+2

print(sum(*a.values())/3)

+1

In your code a is initially int by the time you are doing d = (a)/3 your 'a' is referring to a dictionary. Divide operation is not supported for dictionary, hence the error.

+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

0

tristach605 n = input() for k,v in {**a,**b,**c}.items(): if k==n: print(sum(v)/3)