I suspect strongly that the OP is not meant to simply calculate the exact solution using the standard equations. Doing those calculations programmatically adds no educational value.
Given that the task has been set computationally, and the OP has been asked to provide locations for every multiple of dt in the range, I suspect the OP is intended to use some simple numerical approximation method. The simplest for this would be a simplified (because the equation being solved is so simple) Forward Euler approximation; the simplest and easiest numerical approximation to do.
I suspect that nothing more complicated is required, because the OP clearly has no idea how to do this; this is the first time the OP has encountered anything like this.
The Forward Euler method is very simple, and with these equations, ever more so. Start at time zero, with speed and distance covered also at zero.
Calculate the speed at the next time step. From that get the new distance covered in the time gap, dt. Add that to distance covered so far. Each one of these calculations is used to satisfy the task
"prints the location of the train in different moments of time." |
Repeat until distance covered equals or exceed twenty km.
It's a shame the accelerations are constant; if they were time dependent, the approximation errors would be very visible. Maybe that will be the next step.