Skip to content

Commit 82c1de3

Browse files
Update swapcase.py
1 parent 0a7d215 commit 82c1de3

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

strings/swapcase.py

+23-4
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,27 @@ def swap_case(input_string: str) -> str:
2727
swapped_list = "".join(list_representation)
2828
return swapped_list
2929

30+
def swap_case(input_string) -> None:
31+
#This method will swap the cases of a given string
32+
# eg: input: s= "Hello" output: t="hELLO"
33+
list_representation=list(input_string)
34+
for i in range(len(list_representation)):
35+
if list_representation[i]>='A' and list_representation[i]<='Z':
36+
m2=ord(list_representation[i])
37+
m1=m2+32
38+
list_representation[i]=chr(m1)
39+
elif list_representation[i]>='a' and list_representation[i]<='z':
40+
m3=ord(list_representation[i])
41+
m4=m3-32
42+
list_representation[i]=chr(m4)
43+
else:
44+
pass
45+
swapped_list=[ele for ele in list_representation]
46+
swapped_list="".join(swapped_list)
47+
return swapped_list
3048

31-
# sample test case
32-
input_string = "Hello"
33-
swapped_string = swap_case(input_string)
34-
print(swapped_string)
49+
if __name__ == "__main__":
50+
# sample test case
51+
input_string = "Hello"
52+
swapped_string = swap_case(input_string)
53+
print(swapped_string)

0 commit comments

Comments
 (0)