From 26180af1d29374c30bf74f11c8c548521215025f Mon Sep 17 00:00:00 2001 From: Tatiparthi Chenchu Jahnavi <54673414+ChenchuJahnavi@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:35:41 +0530 Subject: [PATCH] Create swap-case.py This Program will swap the cases of given string --- strings/swap-case.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 strings/swap-case.py diff --git a/strings/swap-case.py b/strings/swap-case.py new file mode 100644 index 000000000000..49293ab13178 --- /dev/null +++ b/strings/swap-case.py @@ -0,0 +1,22 @@ +def swap_case(s): + #This method will swap the cases of a given string + # eg: input: s= "Hello" output: t="hELLO" + m=list(s) + for i in range(len(m)): + if m[i]>='A' and m[i]<='Z': + m2=ord(m[i]) + m1=m2+32 + m[i]=chr(m1) + elif m[i]>='a' and m[i]<='z': + m3=ord(m[i]) + m4=m3-32 + m[i]=chr(m4) + else: + pass + t=[ele for ele in m] + t="".join(t) + return t + +s=input() +sc= swap_case(s) +print(sc)