Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

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

0 votes
asked Mar 16, 2020 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, 2020 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, 2020 by anonymous
Thank you for  your help.
0 votes
answered Mar 16, 2020 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, 2020 by anonymous
i tried  your suggestion but it  is still showing an error. Thank  you for suggesting though.
0 votes
answered Mar 17, 2020 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.
...