Friday, September 9, 2022

Alternate letters in uppercase in python


A str‌ing (only alphabets) is passed as input.
The printed output should contain alphabets in odd positions in each word in uppercase and alphabets in even positions in a word in lowercase.

Example input/output1:

If the input is 'tREE GiVES us fruiTS', the output should be 'TrEe GiVeS Us FrUiTs

If the input is 'FLoweR iS beauTIFUL', the output should be 'FlOwEr Is BeAuTiFuL'

Solution:

s=list(input().split())

for i in range(len(s)):

    t=""

    for j in range(len(s[i])):

        if j%2!=0:

            t+=s[i][j].lower()

        else:

            t+=s[i][j].upper()

    s[i]=t 

for i in s:print(i,end=" ")

No comments:

Post a Comment

MFIB Comma Separated Integers

Fill in the blanks with code so that the program must accept three integers separated by a space and print them separated by a comma as the ...