Skip to content

Commit 23fa941

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 5a7abde commit 23fa941

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

strings/swapcase.py

+14-13
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,23 @@
1212
def swap_case(input_string) -> str:
1313
"""This method will swap the cases of a given string
1414
eg: input: input_string= "Hello" output: swapped_string="hELLO" """
15-
list_representation=list(input_string)
15+
list_representation = list(input_string)
1616
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)
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)
2525
else:
2626
pass
27-
swapped_list=[ele for ele in list_representation]
28-
swapped_list="".join(swapped_list)
27+
swapped_list = [ele for ele in list_representation]
28+
swapped_list = "".join(swapped_list)
2929
return swapped_list
3030

31-
input_string=input()
32-
swapped_string= swap_case(input_string)
31+
32+
input_string = input()
33+
swapped_string = swap_case(input_string)
3334
print(swapped_string)

0 commit comments

Comments
 (0)