Lowest price ever! Learn Generative AI for 48% less!
Get my discount0
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
4 Answers
+ 2
Change it to:
d = sum( list(a.values())[0] )/3
+ 2
print(sum(*a.values())/3)
+ 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)