Question

test average and grade python

Solution

Verified
Answered 1 year ago
Answered 1 year ago
Step 1
1 of 2

This is the code for a program that can calculate the test average and the grade for each student based on the score.

scores = [("John", 100), ("Mark", 50), ("Ellie", 80), ("Elvis", 40), ("Johny", 66)]


def determine_grade(percentage):
    if percentage >= 90:
        return 'A'
    elif percentage >= 80:
        return 'B'
    elif percentage >= 65:
        return 'C'
    elif percentage >= 50:
        return 'D'
    else:
        return 'F'


for score in scores:
    grade = determine_grade(score[1])
    print(f'{score[0]}: grade={grade}, score={score[1]}')

average = sum(x for x in map(lambda s: s[1], scores)) / len(scores)
print(f"The average score is {average}")

Create an account to view solutions

Create an account to view solutions

Recommended textbook solutions

Computer Organization and Design MIPS Edition: The Hardware/Software Interface 5th Edition by David A. Patterson, John L. Hennessy

Computer Organization and Design MIPS Edition: The Hardware/Software Interface

5th EditionISBN: 9780124077263 (3 more)David A. Patterson, John L. Hennessy
220 solutions
Fundamentals of Database Systems 7th Edition by Ramez Elmasri, Shamkant B. Navathe

Fundamentals of Database Systems

7th EditionISBN: 9780133970777Ramez Elmasri, Shamkant B. Navathe
687 solutions
Introduction to Algorithms 3rd Edition by Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen

Introduction to Algorithms

3rd EditionISBN: 9780262033848 (1 more)Charles E. Leiserson, Clifford Stein, Ronald L. Rivest, Thomas H. Cormen
726 solutions
Introduction to the Theory of Computation 3rd Edition by Michael Sipser

Introduction to the Theory of Computation

3rd EditionISBN: 9781133187790 (1 more)Michael Sipser
389 solutions

More related questions

1/4

1/7