Python Forum

Full Version: How to Use Python for solving the following physics question. Python Code required
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How to Use Python for solving the following physics question. Python Code and procedure required
A car of mass 1600kg moving with an initial velocity of 18ms-1 (ms power -1) hits another stationary car of mass 1400kg and they lock together. With what velocity do they move after an elastic collision?
Data Given;
m1=1600 kg
m2= 1400 kg
u1= 18 ms-1
u2= 0
v1=v2=v
to find v=?

Formula: m1u1+m2u2=m1v1+m2v2

Solution:
m1u1+m2u2=m1v1+m2v2
1600x18+1400x0=1600+1400v
28800+0=3000v
v=28800/3000
v=9.6 ms-1 Answer
If they lock together, the collision is not elastic. Besides that, why do you need python if you already computed the result by hand?
Thanks! But i want to express in python code
(Dec-17-2019, 10:44 AM)ishahid Wrote: [ -> ]But i want to express in python code
In this case, open your favourite IDE and start writing code. You know how to solve it by hand, now transform this into python code. If you face difficulties - post your code in python tags, full traceback if you get any - in error tags and ask specific questions.
I am a beginner . Please help for transforming in python code Thanks
If we write it for you, you will always stay a beginner
Here's a beginning, leaving some blanks for you to fill in and figure out:
# Data
m1=1600 
m2= 1400 
u1= 18
u2= 0

#momentums
mom1=m1*u1
#put similar formula for the second object initial momentum here, call it mom2
mom3=mom1+mom2#combined momentum

#solution
velociraptor = mom3/(#the sum of the masses)
print(velociraptor)
Hi jefsummers , Thanks for Help.!
Hi @ishahid,

There are many ways to solve this physics question. but among this i found best way to solve this.

# Use input() method to gather given information
#Example:
m1 = input() # After running the code, the executioner will ask for the value

# Use print() to show the steps and working:
print('Formula used: m1u1 + m2u2 = (m1 + m2)v1')

# print final answer:
print('v = ' + str(v1))
If your question is even more fundamental for how to use Python, read here:
w3schools - Python

Hope this helps.