# My Finished Getting Ready for Physics Class Project

I just finished the Getting Ready for Physics Class project! I added more functions than the project actually asked me to do, so I thought I’d share my code.

``````train_mass = 22680
train_acceleration = 10
train_distance = 100

pencil_mass = 0.006

falcon_9_velocity = 2000
falcon_9_time = 3600
falcon_9_length = 70

ti_europe_mass = 5*10**8
ti_oceania_mass = 5*10**8
distance = 100

blue_frequency = 6.5 * 10**14

spring_constant = 80
spring_extention = 0.15

def f_to_c(f_temp):
c_temp = (f_temp - 32) * 5/9
return c_temp
def c_to_f(c_temp):
f_temp = c_temp * (9/5) + 32
return f_temp
def f_to_k(f_temp):
k_temp = f_to_c(f_temp) + 273.15
return k_temp
def c_to_k(c_temp):
k_temp = c_temp + 273.15
return k_temp

f100_in_celsius = f_to_c(100)
c0_in_fahrenheit = c_to_f(0)
f75_in_kelvin = f_to_k(75)
c15_in_kelvin = c_to_k(15)

def get_force(mass, acceleration):
force = mass * acceleration
return force

train_force = get_force(train_mass, train_acceleration)
print("The GE train supplies " + str(train_force) + " Newtons of force.")
print("\n")

def get_energy(mass, c = 3*10**8):
energy = mass * c**2
return energy

pencil_energy = get_energy(pencil_mass)
print("A " + str(pencil_mass) + " pencil supplies " + str(pencil_energy) + " Joules.")
print("\n")

def get_work(mass, acceleration, distance):
work = get_force(mass, acceleration) * distance
return work
train_work = get_work(train_mass, train_acceleration, train_distance)
print("The GE train does " + str(train_work) + " Joules of work over " + str(train_distance) + " metres.")
print("\n")

def time_dilation(time, velocity, c = 3*10**8):
dilation = time/(1 - (velocity**2/c**2))**0.5
return dilation

def length_contraction(length, velocity, c = 3*10**8):
contraction = length * (1 - (velocity**2/c**2))**0.5
return contraction

falcon_9_time_dilation = time_dilation(falcon_9_time, falcon_9_velocity)
print("A Falcon 9 rocket travelling at " + str(falcon_9_velocity) + " m/s travels for " + str(falcon_9_time) + " seconds, while a stationary observer on Earth experiences " + str(falcon_9_time_dilation) + " seconds.")
print("\n")
falcon_9_length_contraction = length_contraction(falcon_9_length, falcon_9_velocity)
print("To a stationary observer a " + str(falcon_9_length) + " metre Falcon 9 rocket appears to be " + str(falcon_9_length_contraction) + " metres long.")
print("\n")

def gravitational_attraction(mass1, mass2, distance_of_radii, gravitational_constant = 6.674*10**-11):
gravity = gravitational_constant*((mass1 * mass2)/distance**2)
return gravity

europe_oceania_gravity = gravitational_attraction(ti_europe_mass, ti_oceania_mass, distance)
print("The gravitational attraction between the supertankers, TI Europe and TI Oceania, is " + str(europe_oceania_gravity) + " Newtons.")
print("\n")

def photon_energy(frequency, h=6.63*10**-34):
energy = h * frequency
return energy

blue_energy = photon_energy(blue_frequency)
print("The energy of a photon of blue light is " + str(blue_energy) + " Joules.")
print("\n")

def elastic_potential(k, x):
energy = 0.5 * k * x**2
return energy

spring_energy = elastic_potential(spring_constant, spring_extention)
print("The energy of a spring with a spring constant of " + str(spring_constant) + " N/m compressed by " + str(spring_extention) + " metres is " + str(spring_energy) + " Joules.")
``````
3 Likes