Skip to content
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions strings/swapcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""
Example to show how this method works
>>> swap_case("Hello")
hELLO
>>> swap_case("water")
WATER

"""

def swap_case(input_string:str):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please provide return type hint for the function: swap_case. If the function does not return a value, please provide the type hint as: def function() -> None:

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

if __name__ == "__main__":
# sample test

Check failure on line 27 in strings/swapcase.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W291)

strings/swapcase.py:27:18: W291 Trailing whitespace
input_string="Hello"
swapped_string = swap_case(input_string)
print(swapped_string)


Check failure on line 32 in strings/swapcase.py

View workflow job for this annotation

GitHub Actions / ruff

Ruff (W293)

strings/swapcase.py:32:1: W293 Blank line contains whitespace
Loading