File tree 2 files changed +33
-23
lines changed
2 files changed +33
-23
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments