File tree 1 file changed +23
-4
lines changed
1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change @@ -27,8 +27,27 @@ def swap_case(input_string: str) -> str:
27
27
swapped_list = "" .join (list_representation )
28
28
return swapped_list
29
29
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
30
48
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 )
You can’t perform that action at this time.
0 commit comments