Python Forum

Full Version: Name Error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am getting Name Error every time I am trying to execute a program.
My code and everything is right though.
Name Error: Name 'b' is not defined

def celsius_to_fahrenheit(temp):
 newTemp = (9/5)* temp +32
print("The Celsius temperature",temp,"is equivalent to",newTemp,end='')
print("degress Fahrenheit")
output:
def celsius_to_fahrenheit(temp):
 newTemp = (9/5)* temp +32

print("The Celsius temperature",temp,"is equivalent to",newTemp,end='')
print("degress Fahrenheit")
Traceback (most recent call last):

  File "<ipython-input-26-af066734c724>", line 4, in <module>
    print("The Celsius temperature",temp,"is equivalent to",newTemp,end='')
NameError: name 'temp' is not defined
temp and newTemp are defined inside the function, thus no where else would know what they are unless you return them. The print function calls are outside of the function, not in it.