-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHR Swap case.py
53 lines (51 loc) · 1.1 KB
/
HR Swap case.py
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# You are given a string and your task is to swap cases. In other words, convert all lowercase letters to uppercase letters and vice versa.
#
# For Example:
#
# Www.HackerRank.com → wWW.hACKERrANK.COM
# Pythonist 2 → pYTHONIST 2
# Input Format
#
# A single line containing a string .
#
# Constraints
#
#
# Output Format
#
# Print the modified string .
#
# Sample Input 0
#
# HackerRank.com presents "Pythonist 2".
# Sample Output 0
#
# hACKERrANK.COM PRESENTS "pYTHONIST 2".
def swap_case(s):
# result = ''
# for char in s:
# if char.isupper():
# x = str(char.lower)
# result += x
# if char.islower():
# x = str(char.upper)
# result += x
x = ''
for char in s:
if char.isupper():
char = char.lower()
x += char
elif char.islower():
char = char.upper()
x += char
else:
x += char
result = x
return result
if __name__ == '__main__':
s = input()
result = swap_case(s)
print(result)
#ALT
string_input = input()
print(string_input.swapcase())