Skip to content

Commit e29f565

Browse files
committed
new solution
1 parent 17b7d7a commit e29f565

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

‎08_apples_and_bananas/solution0.py‎

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : Ken Youens-Clark <kyclark@gmail.com>
4+
Date : 2020-03-24
5+
Purpose: Rock the Casbah
6+
"""
7+
8+
import argparse
9+
import os
10+
import sys
11+
12+
13+
# --------------------------------------------------
14+
def get_args():
15+
"""Get command-line arguments"""
16+
17+
parser = argparse.ArgumentParser(
18+
description='Rock the Casbah',
19+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
20+
21+
parser.add_argument('text',
22+
metavar='str',
23+
help='Input text')
24+
25+
parser.add_argument('-v',
26+
'--vowel',
27+
help='The vowel',
28+
metavar='str',
29+
type=str,
30+
choices=list('aeiou'),
31+
default='a')
32+
33+
args = parser.parse_args()
34+
35+
if os.path.isfile(args.text):
36+
args.text = open(args.text).read().rstrip()
37+
38+
return args
39+
40+
41+
# --------------------------------------------------
42+
def main():
43+
"""Make a jazz noise here"""
44+
45+
args = get_args()
46+
text = args.text
47+
vowel = args.vowel
48+
49+
for v in 'aeiou':
50+
text = text.replace(v, vowel)
51+
text = text.replace(v.upper(), vowel.upper())
52+
53+
print(text)
54+
55+
# --------------------------------------------------
56+
if __name__ == '__main__':
57+
main()

0 commit comments

Comments
 (0)