Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

2.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a22d77ddf034bc4e35b1d59 Challenge 352: Contrast Rating 1 29 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".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_contrast_rating("7.5", False), "AAA")`)
}})

get_contrast_rating("4.8", False) should return "AA".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_contrast_rating("4.8", False), "AA")`)
}})

get_contrast_rating("4.2", False) should return "Fail".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_contrast_rating("4.2", False), "Fail")`)
}})

get_contrast_rating("4.5", True) should return "AAA".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_contrast_rating("4.5", True), "AAA")`)
}})

get_contrast_rating("3.0", True) should return "AA".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_contrast_rating("3.0", True), "AA")`)
}})

get_contrast_rating("2.7", False) should return "Fail".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(get_contrast_rating("2.7", False), "Fail")`)
}})

--seed--

--seed-contents--

def get_contrast_rating(ratio, is_large_text):

    return ratio

--solutions--

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"