Constant Naming Audit

Easy ⏱ 8 min 75% acceptance ★★★★★ 4.9
By Python convention, module-level constants are written in UPPER_SNAKE_CASE. Write a function is_constant_name(name) that returns True if the given identifier string name follows this convention (all letters uppercase, words separated by single underscores, no leading/trailing underscore, at least one letter), and False otherwise.

Examples

Example 1
Input
is_constant_name("MAX_RETRIES")
Output
True
Explanation

All-uppercase words joined by underscores.

Example 2
Input
is_constant_name("maxRetries")
Output
False
Explanation

camelCase is not the constant convention.

Example 3
Input
is_constant_name("_HIDDEN")
Output
False
Explanation

Leading underscore disqualifies it here.

Constraints

  • `name` is a non-empty string of letters/digits/underscores.
  • Digits are allowed inside the name but the name must contain at least one letter.

Topics

Variables & Data Typesnaming conventions

Companies

AccentureCapgeminiCognizant

Hints

Hint 1

Check `name == name.upper()` and `name` has no leading/trailing underscore.

Hint 2

Split on "_" and make sure no piece is empty (rules out doubled or edge underscores).

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.