is it possible to for-loop through a list with integers and use the += operator to add the integers to a variable with 0? eg:
length = [3, 2]
grades = [1, 1, 1, 5, 4]
avg_grade = []
c = 0
d= 0
r = 0
x = 0
for t in length:
b = 0
for s in range(d, d + t):
b += grades[s]
d += 1
r += 1
if r == length[x]:
c = b / t
avg_grade.append(c)
x += 1
r = 0
I always receive:
TypeError: unsupported operand type(s) for +=: ‘int’ and ‘types.GenericAlias’
Is there another way to calculate the average grades? Maybe with sum()?
Thanks!
New contributor
Blue7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.