← Intro to programming with Python
Mini project: username maker
Turn a messy full name into a tidy username and initials.
Websites often build a username from your real name. That takes several small text steps in a row: tidy the name, split it into first and last, then take pieces of each. Doing one step per line, with a variable for each result, keeps every step easy to check.
full_name = " Kofi Mensah "
parts = full_name.strip().lower().split()
first = parts[0] # "kofi"
last = parts[1] # "mensah"
print(first[0] + last) # kmensahparts is a list of words. parts[0] is the first word and parts[1] is the second, just like characters in a string.
Common mistake: forgetting to strip. split() actually ignores extra spaces, but other tools like slicing do not, so tidy early.