Computer Science, asked by harleenk5491, 10 months ago

Write a program that reads a string and then prints a string that capitalizes every other letter in the string e.g., passion becomes pAsSiOn.

Answers

Answered by shyam143nikki
0

Answer:

Use camelcase to capitalize letters like this.

Answered by presentmoment
1

The program to capitalize every second character of a sting in python is :

Explanation:

We are using the upper() and lower() function to make every other character capital in the string.

# initialize string

s = "passion"

 # print original string

print("The original string is : " + str(s))

 # Use upper() + lower() in for loop

# variable to store the alternate cases string

res = ""

for i in range(len(s)):

   if i% 2 :

      res = res + s[i].upper()

   else:

      res = res + s[i].lower()

 

# print the result

print("The alternate case string is : " + str(res))

The output of the above program is given in the image below:

   

   

Attachments:
Similar questions