--- id: 6a22d77ddf034bc4e35b1d59 title: "Challenge 352: Contrast Rating 1" challengeType: 29 dashedName: challenge-352 --- # --description-- Given a contrast ratio and a boolean indicating whether the text is large, return the WCAG rating 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("7.5", False)` should return `"AAA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating("7.5", False), "AAA")`) }}) ``` `get_contrast_rating("4.8", False)` should return `"AA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating("4.8", False), "AA")`) }}) ``` `get_contrast_rating("4.2", False)` should return `"Fail"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating("4.2", False), "Fail")`) }}) ``` `get_contrast_rating("4.5", True)` should return `"AAA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating("4.5", True), "AAA")`) }}) ``` `get_contrast_rating("3.0", True)` should return `"AA"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating("3.0", True), "AA")`) }}) ``` `get_contrast_rating("2.7", False)` should return `"Fail"`. ```js ({test: () => { runPython(` from unittest import TestCase TestCase().assertEqual(get_contrast_rating("2.7", False), "Fail")`) }}) ``` # --seed-- ## --seed-contents-- ```py def get_contrast_rating(ratio, is_large_text): return ratio ``` # --solutions-- ```py def get_contrast_rating(ratio, is_large_text): ratio = float(ratio) 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" ```