[Tutor] Beginner problem: name 'convertToFahrenheit' is not defined
Joseph Bae
joeturf at gmail.com
Fri Aug 15 01:08:30 CEST 2008
Hi all,
I'm new to Python (and programming in general) and need some help!
Here is my code so far for a temperature conversion program (converts
between Fahrenheit and Celsius):
temp = input("Enter A Number : ")
convertTo = raw_input("Convert To (F)ahrenheit or (C)elsius? : ")
if convertTo == "F":
convertedTemp = convertToFahrenheit(temp)
print "%d Celsius = %d Fahrenheit" % (temp, convertedTemp)
else:
convertedTemp = convertToCelsius(temp)
print "%d Fahrenheit = %d Celsius" % (temp, convertedTemp)
def convertToFahrenheit(t):
tF = (9.0/5.0) * (t + 32)
return tF
def convertToCelsius(t):
tC = (9.0/5.0) * (t - 32)
return tC
It worked fine without having extra functions but once I put
convertToFahrenheit and convertToCelsius in (just for practice really), this
happened:
Enter A Number : 50
Convert to (F)ahrenheit or (C)elsius? : F
Traceback (most recent call last):
File "TemperatureConverter.py", line 5, in <module>
convertedTemp = convertToFahrenheit(temp)
NameError: name 'convertToFahrenheit' is not defined
This is most likely a very simple error, but can someone please clarify for
me why it's behaving this way?
Thanks!
Joe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080814/6d0ddb34/attachment-0001.htm>
More information about the Tutor
mailing list