Skip to content

Commit 59c1457

Browse files
authored
Merge pull request #1 from Jahnavi998/Jahnavi998-patch-1
Create swapcase.py
2 parents e9e7c96 + 28aecb8 commit 59c1457

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

strings/swapcase.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
"""
2+
Example to show how this method works
3+
>>> swap_case("Hello")
4+
hELLO
5+
>>> swap_case("water")
6+
WATER
7+
8+
"""
9+
10+
def swap_case(input_string:str):
11+
list_representation=list(input_string)
12+
for i in range(len(list_representation)):
13+
if list_representation[i]>="A" and list_representation[i]<="Z":
14+
m2=ord(list_representation[i])
15+
m1=m2+32
16+
list_representation[i]=chr(m1)
17+
elif list_representation[i]>="a" and list_representation[i]<="z":
18+
m3=ord(list_representation[i])
19+
m4=m3-32
20+
list_representation[i]=chr(m4)
21+
else:
22+
pass
23+
swapped_list="".join(list_representation)
24+
return swapped_list
25+
26+
if __name__ == "__main__":
27+
# sample test
28+
input_string="Hello"
29+
swapped_string = swap_case(input_string)
30+
print(swapped_string)
31+
32+

0 commit comments

Comments
 (0)