Skip to content

Commit dc2411f

Browse files
Merge pull request #1 from ChenchuJahnavi/swap-case
Create swap-case.py
2 parents 59ff87d + 26180af commit dc2411f

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

strings/swap-case.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
def swap_case(s):
2+
#This method will swap the cases of a given string
3+
# eg: input: s= "Hello" output: t="hELLO"
4+
m=list(s)
5+
for i in range(len(m)):
6+
if m[i]>='A' and m[i]<='Z':
7+
m2=ord(m[i])
8+
m1=m2+32
9+
m[i]=chr(m1)
10+
elif m[i]>='a' and m[i]<='z':
11+
m3=ord(m[i])
12+
m4=m3-32
13+
m[i]=chr(m4)
14+
else:
15+
pass
16+
t=[ele for ele in m]
17+
t="".join(t)
18+
return t
19+
20+
s=input()
21+
sc= swap_case(s)
22+
print(sc)

0 commit comments

Comments
 (0)