Given a string s write a program to convert uppercase letters into lowercase and lowercase letters into uppercase. Also print the resultant string.
Note: You need to talk the input and do not print anything while taking input.
Input:
The Joy Of Computing
Output
tHE jOY oF cOMPUTING
The code above takes user input and then swaps the cases of each character in the input string.
The first line, s=input()
, waits for the user to input a string and assigns it to the variable s
.
The second line, result=s.swapcase()
, swaps the case of each character in the string using the swapcase()
method. This means that if a character is in uppercase, it will be converted to lowercase, and if it is in lowercase, it will be converted to uppercase. The result of this operation is assigned to the variable result
.
The third line, print(result, end="")
, prints the swapped string to the console. The end=""
argument specifies that the print statement should not end with a newline character. This means that the output will be printed on the same line as the input, with no extra space or new line.