Calculating average and outputting number of cases which were more than and less than average from a list
<p>Task:
Write an algorithm to allow a user to input the maximum and minimum daily temperatures for a number of days until a maximum temperature of 999 is entered.</p>

<p>The program then calculates the average temperature and outputs the number of days that the temperature was above average. It also outputs the number of days that the temperature was negative.</p>

<p>My code that returns with a syntax error: <a href="http://imgur.com/ArMFAk3" rel="nofollow">http://imgur.com/ArMFAk3</a></p>

<p>Reading through the code in the image that you posted and assuming that your algorithm is correct, the following code does what you want (Python 2.7):</p>

<pre><code>import numpy as np

temperatures = []
total = 0
maxtemp = 999
while total &lt; maxtemp:
    data = input("What is your temperature: ")
    temperatures.append(data)
    total = total + data

mean = np.mean(temperatures)
above = temperatures &gt; mean
below = temperatures &lt; mean
print mean
print sum(above)
print sum(below)
</code></pre>

<p>Note what was wrong with your syntax:</p>

<ol>
<li>You try to call <code>len()</code> on an integer</li>
<li>You put a <code>break</code> at the end of a while loop. This means you will only be able to get through the loop once</li>
<li>It appears you try to call <code>len.(above)</code>. There is no need for the period and also <code>len()</code> will return the length of <code>temperatures</code> whereas <code>sum()</code> returns the number of <code>True</code> values</li>
</ol>

python