<div dir="ltr">Hi all,<br><br>I&#39;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(&quot;Enter A Number : &quot;)</span><br style="color: rgb(51, 51, 255);"><span style="color: rgb(51, 51, 255);">convertTo = raw_input(&quot;Convert To (F)ahrenheit or (C)elsius? : &quot;)</span><br><br><span style="color: rgb(51, 51, 255);">if convertTo == &quot;F&quot;:</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 &quot;%d Celsius = %d Fahrenheit&quot; % (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 &quot;%d Fahrenheit = %d Celsius&quot; % (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 &quot;TemperatureConverter.py&quot;, line 5, in &lt;module&gt;</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 &#39;convertToFahrenheit&#39; is not defined</span><br>
<br>This is most likely a very simple error, but can someone please clarify for me why it&#39;s behaving this way?<br><br>Thanks!<br><br>Joe<br></div>