>>> names = ['charlotte hippopotamus turner', 'oliver st. john-mollusc', 'nigel incubator-jones', 'philip diplodocus mallory'] >>> for name in names: print(name.title()) Charlotte Hippopotamus Turner Oliver St. John-Mollusc Nigel Incubator-Jones Philip Diplodocus Mallory
def list_sum(input_lists): sum = 0 for input_list in input_lists: sum = sum + input_list return sum test1 = list_sum([1, 2, 3]) print("expected result: 6, actual result: {}".format(test1)) test2 = list_sum([-1, 0, 1]) print("expected result: 0, actual result: {}".format(test2))
>>> names = ['charlotte hippopotamus turner', 'oliver st. john-mollusc', 'nigel incubator-jones', 'philip diplodocus mallory'] >>> capitalized_name = [] >>> for name in names: capitalized_name.append(name.title()) >>> print(capitalized_name) ['Charlotte Hippopotamus Turner', 'Oliver St. John-Mollusc', 'Nigel Incubator-Jones', 'Philip Diplodocus Mallory'] >>> for index in range(len(names)): names[index] = names[index].title()
>>> for i in range(3): print("Camelot!") Camelot! Camelot! Camelot! >>> print("It's only a model.") It's only a model.
for _ in range(height-2): print("*" + " " * (width-2) + "*")
def starbox(width, height): print("*" * width) for _ in range(height-2): print("*" + " " * (width-2) + "*") print("*" * width)