Windchill nested loops python code equation
<p>I started python only a few months ago and I have been given a task to use a nested loops to calculate wind chill.</p>

<p>I have most of the code completed (I think), however the equation is not working the way it want it to work.</p>

<p>Here is my code at the moment:</p>

<pre><code>def main():
temp = 0
wind = 0
windChill = 13.12 + (.6215 * temp) - (11.37 * wind ** 770.16) + (.3965 * temp * wind **0.16)

for temp in range(-35,15,5):
    print 'temperature is %d' % temp
    for wind in range(0,85,5):
         answer = float(windChill)
         print 'wind is %d calculated wind chill is: %d' % (wind, answer)

main()
</code></pre>

<p>This comes out with this:</p>

<pre><code>temperature is -35
wind is 0 calculated wind chill is: 13
wind is 5 calculated wind chill is: 13
wind is 10 calculated wind chill is: 13
wind is 15 calculated wind chill is: 13
wind is 20 calculated wind chill is: 13
wind is 25 calculated wind chill is: 13
wind is 30 calculated wind chill is: 13
wind is 35 calculated wind chill is: 13
wind is 40 calculated wind chill is: 13
wind is 45 calculated wind chill is: 13
wind is 50 calculated wind chill is: 13
wind is 55 calculated wind chill is: 13
wind is 60 calculated wind chill is: 13
wind is 65 calculated wind chill is: 13
wind is 70 calculated wind chill is: 13
wind is 75 calculated wind chill is: 13
wind is 80 calculated wind chill is: 13
temperature is -30
wind is 0 calculated wind chill is: 13
</code></pre>

<p>I understand why 13 is spited out, it's because if the temp and wind are 0, it comes to the answer 13.12. But if I do the range for the definition of temp and wind, it will not accept a list for the definition.</p>

<p>How do I make it so that the wind chill isn't 13, but the answer which the equation should spit out. </p>

<p>e.g. comes out with this:</p>

<pre><code>temperature is -35
wind is 0 calculated wind chill is: -8.63
wind is 5 calculated wind chill is: -41.29
wind is 10 calculated wind chill is: -45.12
etc.
etc.
</code></pre>

<p>Thank you very much!</p>

<p>If what I have put is simple, and I should just google it, I tried googling it but it makes a table, instead of statements.</p>

<p>Carny.</p>

<p>You must define an actual <em>function</em>. What you have is just an assignment:</p>

<pre><code>temp = 0
wind = 0
windChill = 13.12 + (.6215 * temp) - (11.37 * wind ** 770.16) + (.3965 * temp * wind **0.16)
print(windChill)  # 13.12
</code></pre>

<p>Basically, <code>temp</code> and <code>wind</code> are used with their current values to resolve the expression. <code>windChill</code> then just gets that fixed value assigned to it.</p>

<p>A function would look like this:</p>

<pre><code>def windChill(temp, wind):
    return 13.12 + (.6215 * temp) - (11.37 * wind ** 770.16) + (.3965 * temp * wind **0.16)
</code></pre>

<p>Then <em>call</em> that function in your loop:</p>

<pre><code>for temp in range(-35,15,5):
    print 'temperature is %d' % temp
    for wind in range(0,85,5):
        answer = float(windChill(temp, wind))  # note me!
        print 'wind is %d calculated wind chill is: %d' % (wind, answer)
</code></pre>

<p>Alternatively, you can move the definition of <code>windChill</code> into both loops, so it gets reevaluated every time.</p>

<pre><code>for temp in range(-35,15,5):
    print 'temperature is %d' % temp
    for wind in range(0,85,5):
        answer = 13.12 + (.6215 * temp) - (11.37 * wind ** 770.16) + (.3965 * temp * wind **0.16)
        print 'wind is %d calculated wind chill is: %d' % (wind, answer)
</code></pre>

python