<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">In Python, def is an executable statement. Your function is not defined until the def statement is run by Python. If you move your function definitions earlier in the code so that your functions are defined before they're used, this code will run properly.<div><br></div><div>Josh R.<br><div><br></div><div>On Aug 14, 2008, at 4:08 PM, Joseph Bae wrote:<div><br class="Apple-interchange-newline"><blockquote type="cite"><div dir="ltr">Hi all,<br><br>I'm new to Python (and programming in general) and need some help!<br><br>Here is my code so far for a temperature conversion program (converts between Fahrenheit and Celsius):<br><br><span style="color: rgb(51, 51, 255);"><br> <br>temp = input("Enter A Number : ")</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">convertTo = raw_input("Convert To (F)ahrenheit or (C)elsius? : ")</span><br><br><span style="color: rgb(51, 51, 255);">if convertTo == "F":</span><br style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 51, 255);"> convertedTemp = convertToFahrenheit(temp)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> print "%d Celsius = %d Fahrenheit" % (temp, convertedTemp)</span><br style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 51, 255);">else:</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> convertedTemp = convertToCelsius(temp)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> print "%d Fahrenheit = %d Celsius" % (temp, convertedTemp)</span><br style="color: rgb(51, 51, 255);"> <br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">def convertToFahrenheit(t):</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> tF = (9.0/5.0) * (t + 32)</span><br style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 51, 255);"> return tF</span><br style="color: rgb(51, 51, 255);"><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">def convertToCelsius(t):</span><br style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 51, 255);"> tC = (9.0/5.0) * (t - 32)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);"> return tC</span><br><br><br><br>It worked fine without having extra functions but once I put convertToFahrenheit and convertToCelsius in (just for practice really), this happened:<br> <br>Enter A Number : 50<br>Convert to (F)ahrenheit or (C)elsius? : F<br><span style="color: rgb(255, 0, 0);">Traceback (most recent call last):</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);"> File "TemperatureConverter.py", line 5, in <module></span><br style="color: rgb(255, 0, 0);"> <span style="color: rgb(255, 0, 0);"> convertedTemp = convertToFahrenheit(temp)</span><br style="color: rgb(255, 0, 0);"><span style="color: rgb(255, 0, 0);">NameError: name 'convertToFahrenheit' is not defined</span><br> <br>This is most likely a very simple error, but can someone please clarify for me why it's behaving this way?<br><br>Thanks!<br><br>Joe<br></div> _______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br><a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br></div></div></body></html>