Ask Question
24 January, 11:38

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.

+1
Answers (1)
  1. 24 January, 13:41
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers