Exercise 4 - Award Grades - Solution
BEGIN awardGrade(score) grade = '' IF score <= 44 THEN grade = 'D' ELSE IF score <= 65 THEN grade = 'C' ELSE IF 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' else: if score <= 65: grade = 'C' else: if 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)