-
Notifications
You must be signed in to change notification settings - Fork 20
/
exercise-8-6.py
33 lines (24 loc) · 829 Bytes
/
exercise-8-6.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
import click
def alternating_caps(text):
"""Returns an aLtErNaTiNg cApS version of text"""
alternating_caps_text = ""
should_be_capital = True
for character in text:
if should_be_capital:
alternating_caps_text += character.upper()
should_be_capital = False
else:
alternating_caps_text += character.lower()
should_be_capital = True
return alternating_caps_text
@click.command()
@click.argument("input_filename")
@click.argument("output_filename")
def main(input_filename, output_filename):
"""Converts a text file to an aLtErNaTiNg cApS version"""
with open(input_filename, "r") as f:
text = f.read()
with open(output_filename, "w") as f:
f.write(alternating_caps(text))
if __name__ == "__main__":
main()