File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments