Codecademy Python Course Update 4

Codecademy Python Course Update 4

In this guided project, I implemented functions to do physics calculations: converting temperatures, calculating force, energy, and work.

train_mass = 22680
train_acceleration = 10
train_distance = 100
bomb_mass = 1

# function to convert fahrenheit to celsius 
def f_to_c(f_temp):
  c_temp = (f_temp - 32) * 5/9
  return c_temp

#testing the f_to_c function
f100_in_celsius = f_to_c(100)
print(f100_in_celsius)

# function to convert celsius to fahrenheit
def c_to_f(c_temp):
  f_temp = (c_temp * 9/5) + 32
  return f_temp

#testing the c_to_f function
c0_in_fahrenheit = c_to_f(0)
print(c0_in_fahrenheit)

# function to calculate force using mass and acceleration
def get_force(mass, acceleration):
  return mass * acceleration

# Calculate the force exerted by the GE train
train_force = get_force(train_mass, train_acceleration)
print(train_force)
print("The GE train supplies", train_force, " Newtons of force.")

# function to calculate energy using mass and c constant
def get_energy(mass, c = 3*10**8):
  return mass * c**2

# calculating the energy produced by a  1kg bomb
bomb_energy = get_energy(bomb_mass)
print(bomb_energy)
print("A 1kg bomb supplies", bomb_energy, " Joules.")

# function to calculate work using mass, acceleration and distance
def get_work(mass, acceleration, distance):
  return (get_force(mass, acceleration)) * distance

# calculating the work exerted by a train
train_work = (get_work(train_mass, train_acceleration, train_distance))
print("The GE train does", train_work, "Joules of work over", train_distance, "meters.")

Comments are closed.