asked 96.0k views
5 votes
Define a function below called process_grades. The function takes one argument: a list of integers. Each integer in the list corresponds to a student's grade in a class. Complete the function such that it returns a new list where the integer grades are replaced by letter grades. For this question, use a standard grading scale without +/- grade, as follows A: 90-100 B: 80-89 C: 70-79 D: 60-69 F: < 60 For example, given the list [90, 85, 85, 72], the function should return ['A','B','B','C'].

asked
User Fematich
by
8.5k points

1 Answer

5 votes

Answer:

Following are the code in the Python Programming Language.

#define function

def process_grades(std_grades):

result = [] #list type variable

for grades in std_grades: #set for loop

if 90<=grades<=100: #set if statement

lettersGrade = 'A' #variable initialization

elif 80<=grades<=89: #set elif statement

lettersGrade = 'B' #variable initialization

elif 70<=grades<=79: #set elif statement

lettersGrade = 'C' #variable initialization

elif 60<=grades<=69: #set elif statement

lettersGrade = 'D' #variable initialization

else:

lettersGrade = 'F' #variable initialization

result.append(lettersGrade) #append the value of lettersGrade in result

return result #print the value of the variable result

print(process_grades([90, 85, 85, 72])) #call the function

Output:

['A', 'B', 'B', 'C']

Step-by-step explanation:

Here, we define the function "process_grades" and pass an argument in the parameter list is "std_grades" in which we pass the grades of the students.

Then, we set the list data type variable "result" i9n which we store the grades of the students.

Then, we set the for loop and pass the condition.

Then, we set the "if-elif" statement and pass the conditions as given in the question.

Then, we append the value of the variable "lettersGrade" in the variable "result".

Finally, we call then function.

answered
User Dhaval Chauhan
by
7.1k points

No related questions found