Q. Write a python program as per specifications given below:


(1). Repeatedly prompt for a sentence (string ) or for “q” to quit. 

(2). Upon input of a sentence s, print the string produced form s by converting each lower case letter to upper case and each upper case letter to lower case.

(3). All other character are left unchanged.


You can understand by Watching video :-



Answer :-

while True :
    sen = input("Enter a sentence (for quit enter q or Q)= ")
    if sen == "Q" or sen=="q" :
        break
    else :
        for c in range(len (sen)) :
            if  sen[c].isupper() :
                print (sen[c] .lower() , end="" )
            elif sen[c].islower() :
                print (sen[c] .upper() , end="" )
            else :
                print(sen[c] , end="")
        print()

Output :-

Enter a sentence (for quit enter q or Q)= This is @Path Walla Website .
tHIS IS @pATH wALLA wEBSITE .
Enter a sentence (for quit enter q or Q)= Python is My LOVE.???
pYTHON IS mY love.???
Enter a sentence (for quit enter q or Q)= q

>>> 


Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post