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?
CodePudding user response:
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
CodePudding user response:
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