Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a function initials(name) that gives the capital initials of a name, so that "asha kumari rao" gives "AKR". It must cope with extra spaces and with capital letters in the wrong place, such as " aSHA kUMARI ", which gives "AK". What does it give for an empty text?
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, go through the solution one step at a time, and check each step against your own.
Plan. split() with no argument cuts the name into words and drops the extra spaces. Take the first letter of each word, make it a capital, and join.
Check.
"asha kumari rao" has three words, with the first letters a, k, r: "AKR"." aSHA kUMARI ": two words after the extra spaces are dropped: "AK". Taking the first letter and making it a capital fixes the wrong capitals."".Answer: "AKR", "AK" and "".
Log in to join the discussion.
Loading…