<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>