Files
freecodecamp--freecodecamp/curriculum/challenges/english/blocks/daily-coding-challenges-python/69272dcf1c24b44fd79137c3.md
T
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.3 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69272dcf1c24b44fd79137c3 Challenge 140: SCREAMING_SNAKE_CASE 29 challenge-140

--description--

Given a string representing a variable name, return the variable name converted to SCREAMING_SNAKE_CASE.

The given variable names will be written in one of the following formats:

  • camelCase
  • PascalCase
  • snake_case
  • kebab-case

In the above formats, words are separated by an underscore (_), a hyphen (-), or a new word starts with a capital letter.

To convert to SCREAMING_SNAKE_CASE:

  • Make all letters uppercase
  • Separate words with an underscore (_)

--hints--

to_screaming_snake_case("userEmail") should return "USER_EMAIL".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("userEmail"), "USER_EMAIL")`)
}})

to_screaming_snake_case("UserPassword") should return "USER_PASSWORD".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("UserPassword"), "USER_PASSWORD")`)
}})

to_screaming_snake_case("user_id") should return "USER_ID".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("user_id"), "USER_ID")`)
}})

to_screaming_snake_case("user-address") should return "USER_ADDRESS".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("user-address"), "USER_ADDRESS")`)
}})

to_screaming_snake_case("username") should return "USERNAME".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("username"), "USERNAME")`)
}})

to_screaming_snake_case("my_variable_name") should return "MY_VARIABLE_NAME".

({test: () => { runPython(`
from unittest import TestCase
TestCase().assertEqual(to_screaming_snake_case("my_variable_name"), "MY_VARIABLE_NAME")`)
}})

--seed--

--seed-contents--

def to_screaming_snake_case(variable_name):

    return variable_name

--solutions--

import re
def to_screaming_snake_case(variable_name):
    temp = re.sub(r'[-_]+', ' ', variable_name)
    temp = re.sub(r'([a-z0-9])([A-Z])', r'\1 \2', temp)
    words = temp.strip().split()
    return '_'.join(words).upper()