Name the naming style

Style guides say which naming style each kind of name uses. Recognise the style of a name.

What to build

A program that classifies identifiers by their naming style.

Requirements

  • UPPER_CASE: only the characters A-Z, 0-9 and _, with at least one letter.
  • snake_case: only the characters a-z, 0-9 and _, with at least one letter.
  • CamelCase: starts with an upper-case letter, has only letters and digits, and has at least one lower-case letter.
  • Anything else, including a name that starts with a digit, is other.
  • Print NAME: STYLE for each name, in order.

Input

The first line has n (1 to 50). Each of the next n lines is one name without spaces.

Output

n lines like total_price: snake_case.

Constraints

1 ≤ n ≤ 50.

Example

Input:

4
total_price
MAX_SIZE
LinkedList
my-var

Output:

total_price: snake_case
MAX_SIZE: UPPER_CASE
LinkedList: CamelCase
my-var: other

Why it works

The three styles have disjoint character rules, so testing the characters of each name against them gives exactly one answer; everything that fits none of them is other.

Examples

Example 1 · Input
4
total_price
MAX_SIZE
LinkedList
my-var
Expected output
total_price: snake_case
MAX_SIZE: UPPER_CASE
LinkedList: CamelCase
my-var: other
Example 2 · Input
3
x
X
Xy
Expected output
x: snake_case
X: UPPER_CASE
Xy: CamelCase

Prompts inside input() are ignored when checking, so input("n: ") is fine.

Hints

Hint 1

Use the string methods isupper() and islower() on the whole name, and any(c.isalpha() ...) to find a letter.

Hint 2

A name that is empty or starts with a digit is other.

Hint 3

CamelCase starts with an upper-case letter, has only letters and digits, and has some lower-case letter.

Solution

Show one correct solution (try it yourself first)
n = int(input())
for _ in range(n):
    name = input().strip()
    has_letter = any(ch.isalpha() for ch in name)
    if not name or name[0].isdigit():
        style = "other"
    elif has_letter and all(ch in "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_" for ch in name):
        style = "UPPER_CASE"
    elif has_letter and all(ch in "abcdefghijklmnopqrstuvwxyz0123456789_" for ch in name):
        style = "snake_case"
    elif name[0].isupper() and name.isalnum() and any(ch.islower() for ch in name):
        style = "CamelCase"
    else:
        style = "other"
    print(f"{name}: {style}")

▶ Open this solution in the compiler, then press Visualize to watch it run step by step

Lesson: Code review and style →