Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def swap(my_string):
- # initialise result to ""
- result = ""
- # go through the characters of the string
- for i in range(len(my_string)):
- current_char = my_string[i]
- # if current character is uppercase, swap it to lower
- if current_char.isupper():
- result = result + current_char.lower()
- # if current character is lowercase, swap it to upper
- elif current_char.islower():
- result = result + current_char.upper()
- else:
- result = result + current_char
- return result
- # lower(), upper(), isupper(), islower()
- my_string = "Henry"
- print(swap(my_string))
- assert swap(my_string) == "hENRY"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement