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 1/2] 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) From 93f12f4bc90b3dd84f80dd16deb734a6f7f6fbdd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 4 Oct 2024 12:21:26 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/swap-case.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/strings/swap-case.py b/strings/swap-case.py index 49293ab13178..c3714affca44 100644 --- a/strings/swap-case.py +++ b/strings/swap-case.py @@ -1,22 +1,23 @@ def swap_case(s): - #This method will swap the cases of a given string + # This method will swap the cases of a given string # eg: input: s= "Hello" output: t="hELLO" - m=list(s) + 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) + 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) + t = [ele for ele in m] + t = "".join(t) return t -s=input() -sc= swap_case(s) + +s = input() +sc = swap_case(s) print(sc)