-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswapcase.py
34 lines (32 loc) · 898 Bytes
/
swapcase.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
"""
SWAP CASE
CHALLENGE DESCRIPTION: Write a program which swaps letters' case in a sentence. All non-letter characters should remain
the same.
INPUT SAMPLE: Your program should accept as its first argument a path to a filename. Input example is the following
Hello world!
JavaScript language 1.8
A letter
OUTPUT SAMPLE: Print results in the following way.
hELLO WORLD!
jAVAsCRIPT LANGUAGE 1.8
a LETTER
"""
import sys
test_cases = open(sys.argv[1], 'r')
lines = [line for line in test_cases]
for line in lines:
if line == "":
break
counter = 0
storage = []
for char in line:
if char.isalpha():
if char.islower():
storage.append(char.upper())
else:
storage.append(char.lower())
counter += 1
elif char != '\n':
storage.append(char)
print ''.join(storage)
test_cases.close()