--- id: 6a22d77ddf034bc4e35b1d5a title: "Challenge 353: Contrast Rating 2" challengeType: 29 dashedName: challenge-353 --- # --description-- Given two relative luminance values and a boolean indicating whether the text is large, return the WCAG contrast rating using the following method: Calculate the contrast ratio by adding 0.05 to each luminance value, then dividing the lighter one by the darker one. The lighter one will always be the first argument. Return the rating based on the contrast ratio using the following table: | Rating | Normal Text | Large Text | |--------|-------------|------------| | `"AAA"` | 7.0+ | 4.5+ | | `"AA"` | 4.5+ | 3.0+ | | `"Fail"` | below 4.5 | below 3.0 | # --hints-- `get_contrast_rating(1.0, 0.0, False)` should return `"AAA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating(1.0, 0.0, False), "AAA")`) }}) ``` `get_contrast_rating(0.9015, 0.1364, False)` should return `"AA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating(0.9015, 0.1364, False), "AA")`) }}) ``` `get_contrast_rating(0.8965, 0.1628, False)` should return `"Fail"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating(0.8965, 0.1628, False), "Fail")`) }}) ``` `get_contrast_rating(0.7469, 0.0957, True)` should return `"AAA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating(0.7469, 0.0957, True), "AAA")`) }}) ``` `get_contrast_rating(0.7489, 0.2018, True)` should return `"AA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating(0.7489, 0.2018, True), "AA")`) }}) ``` `get_contrast_rating(0.6571, 0.1974, True)` should return `"Fail"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating(0.6571, 0.1974, True), "Fail")`) }}) ``` # --seed-- ## --seed-contents-- ```py def get_contrast_rating(l1, l2, is_large_text): return l1 ``` # --solutions-- ```py def get_contrast_rating(l1, l2, is_large_text): ratio = (l1 + 0.05) / (l2 + 0.05) if is_large_text: if ratio >= 4.5: return "AAA" if ratio >= 3.0: return "AA" else: if ratio >= 7.0: return "AAA" if ratio >= 4.5: return "AA" return "Fail" ```