Python 3 Functions - Physics Class project

Iโ€™m very new here. This is my first post.
Here is the code of my try at the 3rd Lesson in Python: Functions.
Getting Ready for Physics Class.
I followed the instructions and it seems working, so I might have some code mistakes. Trying to grasp the concept of it :slight_smile:

</
train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1

#1
def f_to_c(f_temp):
c_temp = (f_temp - 32) * 5/9
return c_temp
#2
f100_in_celsius = f_to_c(100)
print(โ€œ100 Degree Temperature Fahrenheit is in Celsius:โ€, f100_in_celsius, โ€œCโ€)
#3
def c_to_f(c_temp):
f_temp = c_temp * (9/5) + 32
return f_temp
#4
c0_in_fahrenheit = c_to_f(0)
print(โ€œZero Tempretature Celsius is in Fahrenheit:โ€, c0_in_fahrenheit, โ€œFโ€)
#5
def get_force(mass, acceleration):
force= mass * acceleration
return force
#6

print(get_force(train_mass, train_acceleration))

train_force = get_force(train_mass, train_acceleration)
print(train_force)
#7
print(โ€œThe GE train supplies " + str(train_force) + " Newtons of force.โ€)
#8
def get_energy(mass, c):
c = 3108
energy = mass * c
2
return energy
#9
bomb_energy = get_energy(bomb_mass, c= 3
10**8)
print(bomb_energy)
#10
print(โ€œA 1kg bomb supplies " + str(bomb_energy) + " Joules.โ€)
#11
def get_work(mass, acceleration, distance):
work = get_force(mass, acceleration) * distance
return work
#12
train_work = get_work(train_mass, train_acceleration, train_distance)
print(train_work)
print(โ€œThe GE train does " + str(train_work) + " Joules of work over " + str(train_distance) + " meters.โ€)

Let me know if there are any mistakes.
Cheers,

It seems to be well laid out, with good use of variables. If this was production code, you might want to make the comments slightly more descriptive, but thatโ€™s ok.


In future, when you share code on the forums use the guidelines from this post.

1 Like