How can I get the average of a range of inputs?
<p>I have to create a program that shows the arithmetic mean of a list of variables. There are supposed to be 50 grades. </p>

<p>I'm pretty much stuck. Right now IÂ´ve only got:</p>

<pre><code>for c in range (0,50):
    grade = ("What is the grade?")
</code></pre>

<p>Also, how could I print the count of grades that are below 50?</p>

<p>Any help is appreciated.</p>

<p>First of all, assuming <code>grades</code> is a list containing the grades, you would want to iterate over the <code>grades</code> list, and not iterate over <code>range(0,50)</code>.</p>

<p>Second, in every iteration you can use a variable to count how many grades you have seen so far, and another variable that sums all the grades so far. Something like that:</p>

<pre><code>num_grades = 0
sum_grades = 0
for grade in grades:
  num_grades += 1 # this is the same as writing num_grades = num_grades + 1
  sum_grades += sum # same as writing sum_grades = sum_grades + sum
</code></pre>

<p>Now all you need to do is to divide <code>sum_grades</code> by <code>num_grades</code> to get the result.</p>

<pre><code>average = float(sum_grade)s / max(num_grades,1)
</code></pre>

<p>I used the <code>max</code> function that returns the maximum number between num_grades and 1 - in case the list of grades is empty, num_grades will be 0 and division by 0 is undefined.
I used <code>float</code> to get a fraction.</p>

<p>To count the number of grades lower than 50, you can add another variable <code>num_failed</code> and initialize him to <code>0</code> just like num_counts, add an if that check if grade is lower than 50 and if so increase <code>num_failed</code> by 1.</p>

python