-
-
Notifications
You must be signed in to change notification settings - Fork 46.8k
Created swapcase.py #11745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Created swapcase.py #11745
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
26180af
Create swap-case.py
ChenchuJahnavi dc2411f
Merge pull request #1 from ChenchuJahnavi/swap-case
ChenchuJahnavi 93f12f4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2fcf337
swapcase.py
ChenchuJahnavi 5a7abde
Merge pull request #2 from ChenchuJahnavi/ChenchuJahnavi-patch-1
ChenchuJahnavi 23fa941
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b6ea05a
Update swapcase.py
ChenchuJahnavi bd75c72
Update swapcase.py
ChenchuJahnavi 49cdb16
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 04e84b9
Update swapcase.py
ChenchuJahnavi 0a7d215
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 82c1de3
Update swapcase.py
ChenchuJahnavi b8ad822
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] b7d9935
Update swapcase.py
ChenchuJahnavi 1d0a433
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Example to show how this method works | ||
|
||
>>> swap_case ("Hello") | ||
hELLO | ||
|
||
>>> swap_case ("water") | ||
WATER | ||
""" | ||
|
||
|
||
def swap_case(input_string) -> str: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide type hint for the parameter: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please provide type hint for the parameter: |
||
"""This method will swap the cases of a given string | ||
eg: input: input_string= "Hello" output: swapped_string="hELLO" """ | ||
list_representation = list(input_string) | ||
for i in range(len(list_representation)): | ||
if list_representation[i] >= "A" and list_representation[i] <= "Z": | ||
m2 = ord(list_representation[i]) | ||
m1 = m2 + 32 | ||
list_representation[i] = chr(m1) | ||
elif list_representation[i] >= "a" and list_representation[i] <= "z": | ||
m3 = ord(list_representation[i]) | ||
m4 = m3 - 32 | ||
list_representation[i] = chr(m4) | ||
else: | ||
pass | ||
swapped_list = "".join(list_representation) | ||
return swapped_list | ||
|
||
#sample test case | ||
input_string = "Hello" | ||
swapped_string = swap_case(input_string) | ||
print(swapped_string) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.