1.

Write a program that reads a string and then prints a string that capitalizes every other letter in the string. eg : passion becomes pAsSiOn.Add FileQ. 3.2 Upload the screen shot out put of the above program here.​

Answer»

The following co‎des have been written using Python.

s = input("Enter a string: ")

ls = list(s)

for i in range(1, len(s), 2):

   ls[i] = ls[i].capitalize()

es = ""

for i in ls:

   es = es + i

print(es)

Once a string is entered, you form a list out of it. You then start a for loop that traverses through the string and capitalizes every alternate LETTER using the capitalize() method. You then create ANOTHER empty string and concatenate the elements of the list to print the FINAL string.



Discussion

No Comment Found