Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created September 16, 2020 22:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/be6fb980811f9ca3c029fac48610aee5 to your computer and use it in GitHub Desktop.
Save codecademydev/be6fb980811f9ca3c029fac48610aee5 to your computer and use it in GitHub Desktop.
Codecademy export
train_mass = 22680
train_acceleration = 10
train_distance = 100
bomb_mass = 1
# Turn up the Temperature-----------------------------------------
# STEP 1: Defining the function that converts Fahrenheit to Celsius
def f_to_c(f_temp):
c_temp = (f_temp - 32) * 5/9
return c_temp
# STEP 2: Testing the f_to_c function with an input of 100 Fahrenheit
f100_in_celsius = f_to_c(100)
print("100 °F converted to " + str(f100_in_celsius) + " °C")
# STEP 3: Defining the function that converts Celsius to Fahrenheit
def c_to_f(c_temp):
f_temp = c_temp * (9/5) + 32
return f_temp
# STEP 4: Testing the function c_to_f with an input of 0 Celsius
c0_in_fahrenheit = c_to_f(0)
print("0 °C converted to " + str(c0_in_fahrenheit) + " °F")
# Use the Force---------------------------------------------------
# STEP 5: Defining the function that calculate the F = m x a
def get_force(mass, acceleration):
return mass * acceleration
# STEP 6 & 7: Testing the function with a given mass and acceleration (using the variables that were declared in the begining of the code)
train_force = get_force(train_mass, train_acceleration)
print("The GE train supplies " + str(train_force) + " Newtons of force.")
# STEP 8: Defining a function called get_energy that takes mass and c
def get_energy(mass, c=3*10**8):
return mass * c**2
# STEP 9 & 10: Testing and printing out the energy function with the bomb_mass value declared in the begining of the code
bomb_energy = get_energy(bomb_mass)
print("A 1kg bomb supplies " + str(bomb_energy) + " Joules.")
# Do the Work---------------------------------------------------
# STEP 11, 12 & 13: Defining the final function get_work with the paramenters: mass, acceleration and distance. Printing out the result
def get_work(distance):
force = get_force(train_mass, train_acceleration)
return force * distance
train_work = get_work(train_distance)
print("The GE Train does " + str(train_work) + " Joules of work over " + str(train_distance) + " meters.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment