Back to Freecodecamp

Step 4

curriculum/challenges/english/blocks/learn-list-comprehension-by-building-a-case-converter-program/657ef2a86d4e545cec9a85fb.md

latest1.7 KB
Original Source

--description--

In both camel case and pascal case, uppercase characters mark the beginning of new words. To convert the input string to snake case, you will need to check if the characters in the input string are uppercase.

You can use the .isupper() string method to check if a character is uppercase. This method returns True if the character is uppercase and False if it is not.

Inside the for loop, add an if statement to check if the current character is uppercase. Move the pass statement inside the new if statement.

--hints--

You should write a new if statement with char.isupper() as the condition. Remember to add the colon at the end and use the pass keyword to fill the if statement body.

js
({
    test: () => {        
        const commentless_code = __helpers.python.removeComments(code)
        const transformedCode = commentless_code.replace(/\r/g, "");
        const {function_body} = __helpers.python.getDef("\n" + commentless_code, "convert_to_snake_case");
        assert.match(function_body, /\s+if\s+char\.isupper\s*\(\s*\)\s*:\s+pass/);
    }
})

You should replace the pass statement in the loop body with the if statement.

js
({
   test: () => {
        const commentless_code = __helpers.python.removeComments(code)
        const {block_body} = __helpers.python.getBlock(commentless_code, /for\s+char\s+in\s+pascal_or_camel_cased_string\s*/);
        assert.notMatch(block_body, /^\s+pass/);

    }
})

--seed--

--seed-contents--

py
--fcc-editable-region--
def convert_to_snake_case(pascal_or_camel_cased_string):
    snake_cased_char_list = []
    for char in pascal_or_camel_cased_string:
        pass
--fcc-editable-region--