Reputation: 21
I'm fairly new to Python, and I got an idea to write a program to solve the Kinematic Equations used in physics.
vi = input("What is the initial velocity?")
if vi == "/":
dontuse = "vi"
else:
pass
I used this code for each of the values needed (Displacement, Initial Velocity, Final Velocity, Acceleration, and Time)
If the user inputs / as the value, it will not be used in the equation, so I wrote a small assignor to decide which equation to use.
if dontuse == "a":
eq3()
elif dontuse == "d":
eq4()
elif dontuse == "vf":
eq1()
elif dontuse == "t":
eq2()
Initial Velocity (vi) is used in every equation, so I didnt need to add one for that.
def eq1():
# d = Vi*t + 1/2*a*t^2
print("Equation 1!")
answer = # d = Vi*t + 1/2*a*t^2
print("Your answer is:", answer)
My question is here, how would I insert the values of the other variables into an equation that the comupter could solve, then print out?
It may seem like a basic question, but I wasnt sure how to do algebra like this with with Python.
Upvotes: 0
Views: 9083
Reputation: 1
Though am a newbie in coding, the following code might solve the problem:
[ d = vi*t + 1/2*a*t**2 ]
, having Displacement (d), Initial Velocity(vi), Acceleration (a), and Time (t) as variables.def eq1( vi, t, a):
d= vi * t + 1/2 *a * t **2
print (d)
""" calling the function by putting the values of vi, t, and a. you can change the values of your own."""
eq1(3,4,5)
def eq2(vi, t,a, x)
.Upvotes: 0
Reputation: 7100
def eq1(): # d = Vi*t + 1/2*a*t^2 print("Equation 1!") answer = # d = Vi*t + 1/2*a*t^2 print("Your answer is:", answer)
To solve the equation d = Vi*t + 1/2*a*t^2
in python, you would do
answer = Vi*t + .5*a*(t**2)
How does this work??
For the other equations, you really want to solve for one variable, so:
t = (Vf-Vi)/a
Upvotes: 1