#choose suitable values for parameters: v0 = 5.0 g = 9.81 #choose number of intervals n = 10 #compute the step length t_stop = 2*v0/g dt = t_stop/n print('First a for loop:') #i = 0,1,2,...,n for i in range(n+1): #now i = 0,1,2,...,n t = i * dt #t = 0, dt, 2*dt, ..., n*dt=t_stop y = v0 * t - 0.5 * g * t**2 print('%6.2f %6.2f' %(t,y)) print('Then a while loop:') """ Comparing two floats with <= is unsafe because of roundoff errors. We add a small number and use < to avoid this problem. """ eps = 1e-10 t = 0 while t < t_stop + eps: y = v0*t-0.5*g*t**2 print('%6.2f %6.2f' %(t,y)) t += dt """ Terminal> python ball_table1.py First a for loop: 0.00 0.00 0.10 0.46 0.20 0.82 0.31 1.07 0.41 1.22 0.51 1.27 0.61 1.22 0.71 1.07 0.82 0.82 0.92 0.46 1.02 0.00 Then a while loop: 0.00 0.00 0.10 0.46 0.20 0.82 0.31 1.07 0.41 1.22 0.51 1.27 0.61 1.22 0.71 1.07 0.82 0.82 0.92 0.46 1.02 0.00 """