Dremendo Tag Line

Input sentence and convert capital letters to small and vice versa in Python

String Methods - Question 7

In this question, we will see how to input a sentence and convert all the capital letters to small letters and vice versa in Python programming. To know more about string methods click on the string methods lesson.

Q7) Write a program in Python to input a sentence and convert all the capital letters to small letters and vice versa.

Program

ns=""
str=input("Enter a sentence\n")

for i in range(0,len(str)):
    if str[i].isupper()==True:
        ns=ns+str[i].lower()

    elif str[i].islower()==True:
        ns=ns+str[i].upper()

    else:
        ns=ns+str[i]

print(ns)

Output

Enter a sentence
We arE LiVinG in A DemocraTiC CounTRY
wE ARe lIvINg IN a dEMOCRAtIc cOUNtry
video-poster