Python BasicsIntro
Working with Strings
~8 mincode completion
Write clean_name(raw) that takes a messy name and tidies it:
- remove whitespace from both ends
- capitalise it properly
So " grace hopper " becomes "Grace Hopper".
Examples
Extra spaces are removed and each word is capitalised
- Input
- clean_name(" grace hopper ")
- Output
- "Grace Hopper"
Shouty input is brought back to normal capitalisation
- Input
- clean_name("ADA LOVELACE")
- Output
- "Ada Lovelace"
A single name works too
- Input
- clean_name(" turing ")
- Output
- "Turing"
Hints
Hint 1
Work directly with the arguments raw and return the result rather than printing it.
Hint 2
Do not forget to use return value of strip. That step is easy to skip.
Requirements
raw: a string that may have extra spaces and odd capitalisationReturn the trimmed, properly capitalised name.
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~8 min
••••••
3 employers weight this skill
2 frontier labs, 1 AI product company. Top match scores 80.
Python
def clean_name(raw):
"""
Tidy up a name typed by a user.
Args:
raw: a string that may have extra spaces and odd capitalisation
Returns:
The trimmed, properly capitalised name.
"""
# YOUR CODE HERE
pass