now we arrive at the crux of the simulation each time we go through the loopwe want to update the state of the cannonball to move it time seconds farther in its flight let' start by considering movement in the horizontal direction since our specification says that we can ignore wind resistancethe horizontal speed of the cannonball will remain constant and is given by the value of xvel as concrete examplesuppose the ball is traveling at meters per second and is currently meters from the firing point in another secondit will go more meters and be meters from the firing point if the interval is only second (rather than full second)then the cannonball will only fly another ( meters and be at distance of meters you can see that the distance traveled is always given by time xvel to update the horizontal positionwe need just one statementxpos xpos time xvel the situation for the vertical component is slightly more complicatedsince gravity causes the -velocity to change over time each secondyvel must decrease by meters per secondthe acceleration of gravity in seconds the velocity will decrease by ( meters per second the new velocity at the end of the interval is calculated as yvel yvel time to calculate how far the cannonball travels during this intervalwe need to know its average vertical velocity since the acceleration due to gravity is constantthe average velocity will just be the average of the starting and ending velocities(yvel+yvel )/ multiplying this average velocity by the amount of time in the interval gives us the change in height here is the completed loopwhile yvel > xpos xpos time xvel yvel yvel time ypos ypos time (yvel yvel )/ yvel yvel notice how the velocity at the end of the time interval is first stored in the temporary variable yvel this is done to preserve the initial yvel so that the average velocity can be computed from the two values finallythe value of yvel is assigned its new value at the end of the loop this represents the correct vertical velocity of the cannonball at the end of the interval the last step of our program simply outputs the distance traveled adding this step gives us the complete program cball py from math import pisincosradians def main()angle eval(input("enter the launch angle (in degrees)")