This exercise combines split, indexing, upper, and a string accumulator.
initials with one parameter, full_name.initials("Ada Lovelace") returns "A.L.". initials("grace brewster murray hopper") returns "G.B.M.H.". initials("Plato") returns "P.".
Run your code to see the output, then press Submit.
import unittest
class TestInitials(unittest.TestCase):
def test_two_names(self):
self.assertEqual(initials("Ada Lovelace"), "A.L.")
def test_lowercase_names_are_uppercased(self):
self.assertEqual(initials("grace brewster murray hopper"), "G.B.M.H.")
def test_single_name(self):
self.assertEqual(initials("Plato"), "P.")
def initials(full_name):
result = ""
for word in full_name.split():
result += word[0].upper() + "."
return result
print(initials("Ada Lovelace"))
print(initials("grace brewster murray hopper"))
Sign in to join the discussion.
No comments yet. Be the first to ask a question.
Press Run to execute your code, or Submit to test and complete this problem.