Write a program that reads a string and then prints a string that capitalizes every other letter in the string, for example computer becomes cOmPuTeR.

 

Answer:

[Strings] Write a program that reads a string and then prints a string - Long Answer Type Questions (5 Marks each)

Code:

str=input( "Enter a string: " )

l=len(str)

str2= ""

for i in range( 0 ,l):

    if i% 2 == 0 :

        str2 = str2+str[i]

    else:

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

print("New string: "+str2)

 

Explanation:

upper( ) is an in-built method used to convert lowercase letters to uppercase.

Remove Ads Share on WhatsApp
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.