Exercise 4 - Award Grades - Alternate Solution
BEGIN awardGrade(score) grade = '' IF score <= 44 THEN grade = 'D' ELSE IF score >= 45 AND score <= 65 THEN grade = 'C' ELSE IF score >= 66 AND score <= 82 THEN grade = 'B' ELSE grade = 'A' ENDIF ENDIF ENDIF RETURN grade END BEGIN scores = [38, 75, 52, 91, 49] FOR counter = 0 TO LENGTH(scores) score = scores[counter] grade = awardGrade(score) OUTPUT score, grade NEXT counter ENDFOR END
def awardGrade(score): grade = '' if score <= 44: grade = 'D' elif score >= 45 and score <= 65: grade = 'C' elif score >= 66 and score <= 82: grade = 'B' else: grade = 'A' return grade scores = [38, 75, 52, 91, 49] for score in scores: grade = awardGrade(score) print(score, grade)