Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Name Error
#1
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
Reply
#2
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.
Recommended Tutorials:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020