Code doesn't print

Hi, I started the “Getting ready for physics class” project on the “Introduction to programming” and I’m stuck. When I run my code the system doesn’t show an error, but nothing is printed on the console when I use the function print. Can someone please point out what I’m doing wrong?

Here’s the code:

train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1
#farenheit to celsius
def f_to_c(f_temp):
  return [f_temp-32]*5/9
  f100_in_celsius = f_to_c(100)
#celsius to fahrenheit
def c_to_f(c_temp):
  return c_temp*[9/5]+32
  c0_in_fahrenheit = c_to_f(0)
def get_force(mass, acceleration):
  get_force = mass * acceleration
  train_force = get_force(train_mass, train_acceleration)
  return train_force

And here’s the project

Hello, @lima1889, and welcome to the forums!

The way your code is indented, you have 4 functions defined, but no function calls. The functions won’t do anything unless they are called. That is the first issue. Next issue: you have code following return in each of your functions. return hands a value and passes control flow back to the caller (line of code that called the function). Code following an executed return statement is unreachable, and will never be executed.

Take your first function:

def f_to_c(f_temp):
  return [f_temp-32]*5/9
  f100_in_celsius = f_to_c(100)

You actually have a call to the function, but it is inside the function body along with the print() function intended to print the value f100_in_celsius. If you were to outdent the last 2 lines, you would have this:

def f_to_c(f_temp):
  return [f_temp-32]*5/9 #This is incorrect. Square brackets denote a list in python. To alter the order of operations, and perform the subtraction before the multiplication use ()'s.
f100_in_celsius = f_to_c(100) #This line is the caller. It assigns the return value of the function to f100_in_celsius.

Try following this pattern to call your remaining functions, and print their return values.

Also, please review How do I format code in my posts? I edited your post, so your original code formatting is shown.


Oh now I get it. Thank you for your time and patience!

1 Like