Python 3: Getting Ready for Physics Class

Hi

I haven’t long started python. I am on the getting ready for physics class project. I wasn’t getting any errors until i did the last part starting from step 11. I’ve looked over the code for a while but cant figure out where i have gone wrong.

Could someone help me out, i would very much appreciated it. I’ve added the code below but ill put the github link in also just incase i didn’t paste the code correctly.

The error is somewhere from where the function get_work is defined on line 39.

Thanks

Andy

train_mass = 22680
train_acceleration = 10
train_distance = 100

bomb_mass = 1

def f_to_c(f_temp):
  c_temp = (f_temp - 32) * 5/9
  return c_temp

f100_in_celsius = f_to_c(100) 

def c_to_f(c_temp):
  f_temp = c_temp * (9/5) + 32
  return f_temp

c0_in_fahrenheit = c_to_f(0)  

print(c0_in_fahrenheit)

def get_force(mass, acceleration):
  return mass * acceleration

train_force = get_force(train_mass,train_acceleration)

print(train_force)

print("The GE train supplies " + str(train_force) + " Newtons of force.")

def get_energy(mass, c = 3*10**8):
  return mass * c**2

bomb_energy = get_energy(bomb_mass)

print(bomb_energy)

print("A 1kg bomb supplie " + str(bomb_energy) + " Joules")

def get_work(mass, acceleration, distance):
  force = get_force(mass,acceleration)
  return force * distance

train_work = (get_work(train_mass,train_acceleration,train_distance)

print("The GE train does " + str(train_work) + " Joules of work over " + str(train_distance) + " meters.")```

Hello, @dev3868595738, and welcome to the forums.

What specifically does your error message say? I’ll bet it has a clue as to where you should start looking for a syntax error.

2 Likes

You defined the variables train_mass and train_acceleration, but you’re using mass and acceleration in your calculation of force in the last function you declared.

force = get_force(mass, acceleration)

Also, what is the first parenthesis doing in your train_work equation?

1 Like

This is the error im getting. ive looked at it several times but cant seem to work it out.

ahh yeah, there was an extra bracket in the train_work equation. All working now. Thank You :slight_smile:

1 Like

Worked it out, there was an extra bracket on line 43. All working now :slight_smile:

I’m glad you found it. If you’ll look at the error message, notice that the error pointed to the line of code immediately following the line that was missing a closing ) (or had an unnecessary ( depending on how you look at it). To the computer, things are going along fine until it sees a print() statement where it doesn’t belong. Keep that pattern in mind, as you are faced with future error messages. Happy coding!