Knowee
Questions
Features
Study Tools

Imagine you have a text editor that doesn't support automatic capitalization. Write a program that takes your written sentences and capitalizes the first letter of each word, making your text appear more polished and readable. Note: This question helps in clearing the coding tests of Capgemini.Input format :The input consists of a sentence, where words are separated by spaces.Output format :The output prints the modified sentence, after capitalizing the first letter of each word.Refer to the sample output for formatting specifications.Code constraints :length of input sentence < 100Sample test cases :Input 1 :hello worldOutput 1 :Hello WorldInput 2 :tHiS Is a MiXeD CaSe sEnTeNcEOutput 2 :THiS Is A MiXeD CaSe SEnTeNcEInput 3 :hello! how are you? fine, thank you!Output 3 :Hello! How Are You? Fine, Thank You!Note :

Question

Imagine you have a text editor that doesn't support automatic capitalization. Write a program that takes your written sentences and capitalizes the first letter of each word, making your text appear more polished and readable. Note: This question helps in clearing the coding tests of Capgemini.Input format :The input consists of a sentence, where words are separated by spaces.Output format :The output prints the modified sentence, after capitalizing the first letter of each word.Refer to the sample output for formatting specifications.Code constraints :length of input sentence < 100Sample test cases :Input 1 :hello worldOutput 1 :Hello WorldInput 2 :tHiS Is a MiXeD CaSe sEnTeNcEOutput 2 :THiS Is A MiXeD CaSe SEnTeNcEInput 3 :hello! how are you? fine, thank you!Output 3 :Hello! How Are You? Fine, Thank You!Note :

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This problem can be solved using Python's built-in title() function, which capitalizes the first letter of each word in a string. Here is a simple Python program that accomplishes this:

def capitalize_sentence(sentence):
    return sentence.title()

# Test the function
print(capitalize_sentence("hello world"))  # Output: Hello World
print(capitalize_sentence("tHiS Is a MiXeD CaSe sEnTeNcE"))  # Output: THiS Is A MiXeD CaSe SEnTeNcE
print(capitalize_sentence("hello! how are you? fine, thank you!"))  # Output: Hello! How Are You? Fine, Thank You!

This program defines a function capitalize_sentence that takes a sentence as input and returns the sentence with the first letter of each word capitalized. The function is then tested with the provided sample inputs.

Note: The title() function also changes any uppercase letters in the middle of the words to lowercase. If you want to keep the original casing of the rest of the words, you can use a different approach, such as splitting the sentence into words, capitalizing the first letter of each word, and then joining the words back together

This problem has been solved

Similar Questions

Capitalization is writing a word with its first letter as a capital letter. Your task is to capitalize the given word.Note, that during capitalization all the letters except the first one remains unchanged.InputA single line contains a non-empty word. This word consists of lowercase and uppercase English letters. The length of the word will not exceed 103.OutputOutput the given word after capitalization.ExamplesinputCopyApPLeoutputCopyApPLeinputCopykonjacoutputCopyKonjac

If in the English alphabets each consonant is substituted by the immediate preceding letter and each vowel is substituted by the immediate following letter, then the word CAPITALISE will be written as 1 pointBBOJSBMJRFBBOJSBKJRDBBQJSBKJRFBBOJSBKJRF

Pick out the reason for why one should not type in all caps when writing an email?a.Because it's hard to readb.Because it takes up more room and makes the email longerc.Because it's considered "yelling"d.Because it's tough on your keyboard

Write a python program to convert all the letters in the string to uppercasestring = "Hello World"print(string.upper())string = "Hello World"print(string.title())string = "Hello World"print(string.capitalize())string = "Hello World"print(string.Upper())

If in the English alphabets each consonant is substituted by the immediate preceding letter and each vowel is substituted by the immediate following letter, then the word CAPITALISE will be written as

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.