Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
1,556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.32 KB | None | 0 0
  1. #Codecademy Project 2 = Getting Ready for Physics Class
  2.  
  3. #PART 1 - TURN up the Temperature
  4.  
  5. train_mass = 22680
  6. train_acceleration = 10
  7. train_distance = 100
  8. bomb_mass = 1
  9.  
  10. #Step 1 - Write a function called f_to_c that takes an input f_temp, a temperature in Fahrenheit, and converts it to c_temp, that temperature in Celsius. It should then return c_temp. The equation you should use is: Temp (C) = (Temp (F) - 32) * 5/9
  11. def f_to_c(f_temp):
  12.     c_temp = ((f_temp-32) * 5/9);
  13.     return c_temp
  14.  
  15. #Step 2 - Let's test your function with a value of 100 Fahrenheit. Define a variable f100_in_celsius and set it equal to the value of f_to_c with 100 as an input
  16. f100_in_celsius = f_to_c(100);
  17. print(f100_in_celsius);
  18.  
  19. #Step 3 - Write a function called c_to_f that takes an input c_temp, a temperature in Celsius, and converts it to f_temp, that temperature in Fahrenheit. It shoudl then return f_temp. Equation is = [Temp(F) = Temp (C) *(9/5) + 32]
  20. def c_to_f(c_temp):
  21.     f_temp = (c_temp*(9/5) +32);
  22.     return f_temp;
  23.    
  24. #Step 4 - Let's test your function with a value of 0 Celsius. Define a variable c0_in_fahrenheit and set it equal to the value of c_to_f with 0 as an input
  25. c0_in_fahrenheit = c_to_f(0);
  26. print(c0_in_fahrenheit);
  27.  
  28. #PART 2 - USE THE FORCE
  29.  
  30. #Step 5 - Define a function called get_force that takes in mass and acceleration. It should return mass multiplied by acceleration
  31. def get_force(mass, acceleration):
  32.     return(mass*acceleration);
  33.    
  34. #Step 6 - Test get_force by calling it with variables train_mass and train_acceleration. Save the result to a variable called train_force and print it out
  35. train_force = get_force(train_mass,train_acceleration);
  36. print(train_force);
  37.  
  38. #Step 7 - print the string "The GE train supplies X Newtons of force.", with x replaced by train_force.
  39. print("The GE train supplies " + str(train_force) + " Newtons of force.");
  40.  
  41. #Step 8 - Define a function called get_energy that takes in mass and c. c is a constant that is usually set to the speed of light, which is roughly 3 x 10^8. Set c to have a default value of 3*10**8. get_energy should return mass multiplied by c squared.
  42. def get_energy(mass, c=3*10**8):
  43.     return(mass*c**2);
  44.    
  45. #Step 9 - Test get_energy by using it on bomb_mass, with the default value of c. Save the result to a variable called bomb_energy.
  46. bomb_energy = get_energy(bomb_mass);
  47.  
  48. #Step 10 - Print the string “A 1kg bomb supplies X Joules.”, with X replaced by bomb_energy.
  49. print("A 1kg bomb supplies " + str(bomb_energy) + " Joules.");
  50.  
  51. #PART 3 - DO THE WORK
  52.  
  53. #Step 11 - Define a final function called get_work that takes in mass, acceleration, and distance. Work is defined as force multiplied by distance. First, get the force using get_force, then multiply that by distance. Return the result.
  54. def get_work(mass, acceleration, distance):
  55.     return(get_force(mass, acceleration)*distance)
  56.    
  57. #Step 12 - Test get_work by using it on train_mass, train_acceleration, and train_distance. Save the result to a variable called train_work.
  58. train_work = get_work(train_mass, train_acceleration, train_distance);
  59.  
  60. #Step 13 - Print the string "The GE train does X Joules of work over Y meters.", with X replaced with train_work and Y replaced with train_distance.
  61. print("The GE train does " + str(train_work) + " Joules of work over " + str(train_distance) + " meters.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement