how to calculate average of total? it's giving an error can someone tell me how to solve it?

0 votes
asked Mar 16 by anonymous

subject=['Eng','Bio','Mth','Chem','phy']
total=[]
average=0
for item in subject:
  item=int(input('Enter score:'))
  total.append(item)
average=float(total/5)
print(item)
print(sum(total))
print(average)

Output:

average=float(total/5) TypeError: unsupported operand type(s) for /: 'list' and 'int'

3 Answers

0 votes
answered Mar 17 by anonymous
 
Best answer
subject=['Eng','Bio','Mth','Chem','phy']
total=[]
average=0
for item in subject:
  item=int(input('Enter score:'))
  total.append(item)
sum=0
for i in total:
    sum=sum+i
number=len(subject)   
average=float(sum/number)
print("average:%d"%average)
commented Mar 17 by anonymous
Thank you for  your help.
0 votes
answered Mar 16 by A helping coder
Try making the parentheses so that it only wraps around total. I think the reason for the error is that python can’t convert the slash to float.
commented Mar 17 by anonymous
i tried  your suggestion but it  is still showing an error. Thank  you for suggesting though.
0 votes
answered Mar 17 by Anvitha (140 points)

ubject=['Eng','Bio','Mth','Chem','phy']
total=[]
average=0
for item in subject:
  item=int(input('Enter score:'))
  total.append(item)

average=(sum(total))/(len(total))

print(average)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...