Skip to content

Commit 2fcf337

Browse files
swapcase.py
This Method will swap the cases of given string
1 parent 93f12f4 commit 2fcf337

File tree

2 files changed

+33
-23
lines changed

2 files changed

+33
-23
lines changed

strings/swap-case.py

-23
This file was deleted.

strings/swapcase.py

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
"""
2+
Example to show how this method works
3+
4+
>>> swap_case ("Hello")
5+
hELLO
6+
7+
>>> swap_case ("water")
8+
WATER
9+
"""
10+
11+
12+
def swap_case(input_string) -> str:
13+
"""This method will swap the cases of a given string
14+
eg: input: input_string= "Hello" output: swapped_string="hELLO" """
15+
list_representation=list(input_string)
16+
for i in range(len(list_representation)):
17+
if list_representation[i]>='A' and list_representation[i]<='Z':
18+
m2=ord(list_representation[i])
19+
m1=m2+32
20+
list_representation[i]=chr(m1)
21+
elif list_representation[i]>='a' and list_representation[i]<='z':
22+
m3=ord(list_representation[i])
23+
m4=m3-32
24+
list_representation[i]=chr(m4)
25+
else:
26+
pass
27+
swapped_list=[ele for ele in list_representation]
28+
swapped_list="".join(swapped_list)
29+
return swapped_list
30+
31+
input_string=input()
32+
swapped_string= swap_case(input_string)
33+
print(swapped_string)

0 commit comments

Comments
 (0)