Open In App

Python program to calculate acceleration, final velocity, initial velocity and time

Here we can find the acceleration (a), final velocity(v), initial velocity(u) and time(t) using the formula a = (v-u)/t.

At first, functions are defined for all four types of calculations, in which they will accept three inputs and assign the value in three different variables. Then the fourth value is calculated using the acceleration formula and the calculated value is returned. We are going to use the same acceleration formula in different approaches.



Approach: 

Example 1: Initial velocity (u) is calculated.






# code
# Enter final velocity in m/s:
finalVelocity = 10
 
# Enter acceleration in m per second square
acceleration = 9.8
 
#Enter time taken in second
time = 1
initialVelocity = finalVelocity - acceleration * time
print("Initial velocity = ", initialVelocity)

Output:

Initial velocity =  0.1999999999999993

Time complexity: O(1)
Auxiliary space: O(1)

Example 2: Final velocity (v) is calculated.




# code
# initial velocity in m/s:
initialVelocity = 10
 
# acceleration in m per second square
acceleration = 9.8
 
# time taken in second
time = 1
finalVelocity = initialVelocity + acceleration * time
print("Final velocity = ", finalVelocity)

Output:

Final velocity =  19.8

Time Complexity: O(1), constant time complexity as there are no loops or iterations, and the operations are straightforward.
Auxiliary Space: O(1), constant space complexity as the code only uses a fixed amount of memory for the variables.

Example 3: Acceleration (a) is calculated.




#code
# initial velocity in m/s
initialVelocity = 0
 
# final velocity in m/s
finalVelocity = 9.8
 
# time in second
time = 1
 
acceleration = (finalVelocity - initialVelocity) / time
print("Acceleration = ", acceleration)

Output:

Acceleration =  9.8

Example 4: Time (t) is calculated.




# code
#final velocity in m/s
finalVelocity = 10
 
#initial velocity in m/s
initialVelocity = 0
 
#acceleration in meter per second square
acceleration = 9.8
 
time = (finalVelocity - initialVelocity) / acceleration
print("Time taken = ", time)

Output:

Time taken =  1.0204081632653061

Article Tags :