How to Make a Grading Function in Python
The Python Interpreter, called IDLE, serves both as an interactive programming environment and as an excellent utility to perform quick calculations. However, even using IDLE to calculate values requires knowledge of some Python code. In the case of adding numbers and finding their average you should utilize basic looping structures such as the "while" and "for" loops while understanding how to use input functions such as "raw_input."
Instructions
-
-
1
Create a list to hold the grades, a variable to count grades and accept one grade input:
>>>grades = list()
>>>y = 0
>>>grades.append(raw_input('grade: '))
grade: 55
>>> -
2
Create a loop to get grades. In this loop grade entry will stop when you add a negative integer:
>>>while grades[y] >= 0:
. . .grades.append(raw_input('grade: '))
. . . y += 1 -
-
3
Add all the grades from the list together using a for loop:
>>>y = 0
>>>for item in grades:
. . . if item >= 0:
. . . y += item -
4
Find the average of the grades by dividing their sum by the number of positive integers in the grades list:
average = y / (len(grades) - 1)
-
1