Scientific Computing
Create a file gradeAverages.py
and copy the following code into it:
def getAverages(myList):
# FILL IN CODE TO COMPUTE AVERAGE
return 0
numGrades = input("How many grades? ")
numGrades = int(numGrades)
allGrades = []
for i in range(numGrades):
# FILL IN CODE TO GET OTHER GRADES
nextGrade = 0 # what to put?
gradeAverage = getAverages(allGrades)
print("Your grades are: ", allGrades)
print("The grade average is: ", gradeAverage)
This code aims to get from the user the number of grades that will be input (e.g., 5), and then ask the user to input each score individually (e.g., 100, then 90, then 80, then 98, then 97, pressing enter after each score is input in the shell). It should add all grade scores into a list allGrades
. The function getAverages
should compute the average of all scores in that list and return it. Complete the program as described and test that it works. Hint: remember that the input
function returns a string, and int
will convert a string to an integer.
Implement two new functions: getLowestGrade(myList)
and getHighestGrade(myList)
that will return the lowest grade and the highest grade from a given list, respectively. Call these two functions using allGrades
as the input and print the results.
Implement a new function: printGradeDistribution(gradeList)
which will take a list of grades scored from 0 to 100, and keep track of the number of As, Bs, Cs, Ds, and Fs encountered, using the standard grading scale. The function will print out the total of each. For example, if it were given the list [100, 90, 80, 65, 83, 70, 50]
, it would print out
Number of A's: 2
Number of B's: 2
Number of C's: 1
Number of D's: 1
Number of F's: 1
Call this function using allGrades
as input to test that it works.
Work with your team on a proposal for your final project.
Submit your working activity18.py
to Moodle.