Alex Brown - 3 years ago 80

Python Question

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)

It may seem like a basic question, but I wasnt sure how to do algebra like this with with Python.

Recommended for you: Get network issues from **WhatsUp Gold**. **Not end users.**

Answer Source

`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??

- Multiplies initial velocity by time
- Multiplies 1/2 by a
- Multiplies that quantity (step 2) by the square of t

For the other equations, you really want to solve for one variable, so:

```
t = (Vf-Vi)/a
```

Recommended from our users: **Dynamic Network Monitoring from WhatsUp Gold from IPSwitch**. ** Free Download**