Hi,
I dont have any idea why i get an error from here. I follow the instructor exactly
could you advise ?
Thanks,
Jinny
Hi,
I dont have any idea why i get an error from here. I follow the instructor exactly
could you advise ?
Thanks,
Jinny
Pretty much as the error says, train_mass
is not defined. Check your code to ensure that you have defined train_mass
somewhere prior to the function call and that it has been assigned a value.
no this one is want to re-assign the code.
like mass ==> train_mass it should be working right?
Could you please post your entire code here so I can see it? The error is stating that train_mass
is not defined, and so either itâs not listed above, or perhaps when defining that variable there was a typo made and thatâs why it isnât being passed into the function call.
Hello,
is that okay ??
def f_to_c(f_temp):
c_temp= (f_temp -32)* 5/9
return c_temp
f100_in_celsius = f_to_c(100)
print(f100_in_celsius)
def c_to_f(c_temp):
f_temp = c_temp*(9/5)+32
return f_temp
c0_infahrenheit= c_to_f(0)
print(c0_infahrenheit)
def get_force(mass, acceleration):
return mass* acceleration
train_force = get_force(train_mass, train_acce3leration)
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
bomb_energy=get_energy(bomb_mass, c)
print( "A 1kg bomb supplies X Joules., with"+ str(bomb_energy) + "replaced by bomb_energy.")
thanks,
Jinny
Yes thatâs great thank you. The problem is that both train_mass
and train_acceleration
have not been defined, so there are no values to be read into the function. You need to assign train_mass
and train_acceleration
with values before they can be used inside the function call. Also an extra note is just to be careful that you have typoed train_acceleration
as train_acce3leration
so be sure to correct that before running. For example, you should have something like this:
train_mass = 100000
train_acceleration = 30
train_force = get_force(train_mass, train_acceleration)
# will return 3000000
train_mass = 22680
train_acceleration = 10
train_distance = 100
bomb_mass = 1
def f_to_c(f_temp):
return (f_temp - 32) * 5/9
f100_in_celsius = f_to_c(100)
print(f100_in_celsius)
def c_to_f(c_temp):
return (c_temp * 9/5) + 32
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(âThe GE train suppliesâ + str(train_force) + "Newtons of force.â)
Output:
File âscript.pyâ, line 25
print(âThe GE train suppliesâ + str(train_force) + "Newtons of force.â)
^
SyntaxError: EOL while scanning string literal
I cannot seem to get past this, even after following the tute verbatim. I vaguely recall EOL errors being PEBCAK, I just do not recall what it meant.
At the bottom of the editor in the exercise, there should be a âCopy to Clipboardâ button.
The copied code can then be pasted in the forums using the </>
button from the post editor: [How to] Format code in posts
This will allow the formatting of your code to be preserved when posted in the forums. Then we can look for clues as to why your code isnât working. Alternatively, you can post a screenshot.
It may be possible that the quotes you are typing in the code may have some issues with them. In the code you have pasted
print(âThe GE train suppliesâ + str(train_force) + "Newtons of force.â)
there seems to be a mismatch in the quotes, but it is difficult to be sure because directly copy-pasting into posts can warp the text and mess up the formatting even if correct. That is why properly copy-pasting code or a screenshot can help in figuring out what is amiss.
Thank you, I resolved it when making two changes.
One was by adding the definition for Train_force = 1000, and for Train_Acceleration = 30. The other was exactly your catch, where the quotes above âNewtons of force.â were not linked together, When I hit save, it worked.