Write a program that takes a string with multiple words and capitalizes the first letter of each word and forms a new string out of it.



Untitled 34.jpg


str=input( "Enter a string: " )


i= 0

str2= ""

while i<l:

    if i == 0 :

        str2 = str2+str[i].upper()

    elif str[i]== ' ' and str[i+ 1 ]!= ' ' :


        str2=str2+str[i+ 1 ].upper()

        i=i+ 1


        str2 = str2+str[i]

    i=i+ 1

print( "New string: " +str2) 



The first letter of the string and every letter after a blank space is converted to uppercase using the upper( ) method.

Go Ad-free
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh has done his B.Tech from Indian Institute of Technology, Kanpur. He has been teaching from the past 14 years. He provides courses for Maths, Science, Social Science, Physics, Chemistry, Computer Science at Teachoo.