<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">In Python, def is an executable&nbsp;statement. &nbsp;Your function is not defined until the def statement is run by Python. &nbsp;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);">&nbsp;&nbsp;&nbsp; convertedTemp = convertToFahrenheit(temp)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; 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);">&nbsp;&nbsp;&nbsp; convertedTemp = convertToCelsius(temp)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; 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);">&nbsp;&nbsp;&nbsp; tF = (9.0/5.0) * (t + 32)</span><br style="color: rgb(51, 51, 255);"> <span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; 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);">&nbsp;&nbsp;&nbsp; tC = (9.0/5.0) * (t - 32)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">&nbsp;&nbsp;&nbsp; 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);">&nbsp;&nbsp;&nbsp;&nbsp; File "TemperatureConverter.py", line 5, in &lt;module></span><br style="color: rgb(255, 0, 0);"> <span style="color: rgb(255, 0, 0);">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 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 &nbsp;- &nbsp;<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>