Python Forum
Name Error - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Name Error (/thread-7948.html)



Name Error - atik666 - Jan-31-2018

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



RE: Name Error - metulburr - Jan-31-2018

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.