-1

I know how I can get the sum of the numbers themselves in a range, but if I had an equation written in a for-loop such as the following:

for t in range(0,6):
    velocity = (.2*(t**2)) + 3

How could I get Python to add all the outputs of the equation together?

Dante
  • 63
  • 4

2 Answers2

1

Just add the result of the formula to a variable defined outside the for loop

sum_velocity = 0 

for t in range(0,6):
    sum_velocity += (.2*(t**2)) + 3
Sander Bakker
  • 435
  • 1
  • 4
  • 14
1

Just add the value of velocity obtained in every iteration as below:

velocity = 0
for t in range(0,6):
    velocity += (.2*(t**2)) + 3
print (velocity)

Output:

29.0
Bhagyesh Dudhediya
  • 1,800
  • 1
  • 13
  • 16