Ask Question
26 October, 04:19

Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is "hello. my name is Joe. what is your name?" the function should return the string "Hello. My name is Joe. What is your name?". The program should let the user enter a string and then pass it to the function. The modified string should be displayed.

+5
Answers (1)
  1. 26 October, 04:28
    0
    def capitalize_first (st):

    capitilized_list = []

    splitted_st = st. split (". ")

    for x in splitted_st:

    capitilized_list. append (x[0]. capitalize () + x[1:])

    capitilized_st = ". ". join (capitilized_list)

    return capitilized_st

    s = input ("Enter a string: ")

    print (capitalize_first (s))

    Explanation:

    Create a function called capitalize_first that takes one parameter, st

    Create an empty list that will hold the capitalized strings

    Split the given string using split function and put them in the splitted_st

    Create a for loop that iterates through splitted_st. For each string in splitted_st, capitalize their first character and put them in the capitalized_list.

    When the loop is done, join the strings in the capitalized_list using join function and set the joined string to capitilized_st

    Return the capitilized_st

    Ask the user for the string

    Call the function with entered input and print the result
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a program with a function that accepts a string as an argument and returns a copy of the string with the first character of each ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers