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>Try the following. Function isNumber tries to convert the input, which is read as a string, to a float, which I believe convers the integer range too and is the floating-point type in Python 3, which is the version I'm using. The <code>try...except</code> block is similar in a way to the <code>try...catch</code> statement found in other programming languages.</p>

<pre><code>#Checks whether the value is a valid number:
def isNumber( value ):
    try:
        float( value )
        return True
    except:
        return False

#Variables initialization:
numberOfGradesBelow50 = 0
sumOfAllGrades = 0

#Input:
for c in range( 0, 5 ):
    currentGradeAsString = input( "What is the grade? " )
    while not isNumber( currentGradeAsString ):
        currentGradeAsString = input( "Invalid value. What is the grade? " )
    currentGradeAsFloat = float( currentGradeAsString )
    sumOfAllGrades += currentGradeAsFloat
    if currentGradeAsFloat &lt; 50.0:
        numberOfGradesBelow50 += 1

#Displays results:
print( "The average is " + str( sumOfAllGrades / 5 ) + "." )
print( "You entered " + str( numberOfGradesBelow50 ) + " grades below 50." )
</code></pre>

python