forked from prabhupant/python-ds
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoggle_string.py
More file actions
33 lines (28 loc) · 841 Bytes
/
toggle_string.py
File metadata and controls
33 lines (28 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"""
Question
You have been given a String S consisting of uppercase and lowercase English alphabets. You need to change the case of each alphabet
in this String. That is, all the uppercase letters should be converted to lowercase and all the lowercase letters should be converted
to uppercase. You need to then print the resultant String to output.
Source Hackerearth
SAMPLE INPUT
abcdE
SAMPLE OUTPUT
ABCDe
"""
def toggle_string_1(string):
return string.swapcase()
def toggle_string_2(string):
toggle_string=''
for s in string:
if s.isupper():
toggle_string+=s.lower()
elif s.islower():
toggle_string+=s.upper()
else:
toggle_string+=s
return toggle_string
string=input()
# method 1
print(toggle_string_1(string))
# method 2
print(toggle_string_2(string))