Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Ryerson Letter Grade by kurosawa4434
from re import match
TABLE = '''
A+ 90-150%
A 85-89%
A- 80-84%
B+ 77-79%
B 73-76%
B- 70-72%
C+ 67-69%
C 63-66%
C- 60-62%
D+ 57-59%
D 53-56%
D- 50-52%
F 0-49%
'''
def ryerson_letter_grade(pct: int) -> str:
table = filter(len, TABLE.splitlines())
items = map(lambda row: match('(.+) (\d+)-(\d+)%', row).groups(), table)
return [grade for grade, low, high in items if int(low) <= pct <= int(high)][0]
if __name__ == '__main__':
print("Example:")
print(ryerson_letter_grade(45))
# These "asserts" are used for self-checking and not for an auto-testing
assert ryerson_letter_grade(45) == "F"
assert ryerson_letter_grade(62) == "C-"
print("Coding complete? Click 'Check' to earn cool rewards!")
Oct. 13, 2018
Comments: