Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e19386d

Browse files
committed
08_apples_and_bananas
1 parent 5ec7566 commit e19386d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

08_apples_and_bananas/apples.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : Johan Runesson <[email protected]>
4+
Date : 2020-08-04
5+
Purpose: Apples and bananas
6+
"""
7+
8+
import argparse
9+
import os
10+
11+
12+
# --------------------------------------------------
13+
def get_args():
14+
"""Get command-line arguments"""
15+
16+
parser = argparse.ArgumentParser(
17+
description='Apples and bananas',
18+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19+
20+
parser.add_argument('text', metavar='text', help='Input text or file')
21+
22+
parser.add_argument('-v',
23+
'--vowel',
24+
help='The vowel to substitute',
25+
metavar='vowel',
26+
type=str,
27+
choices=list('aeiou'),
28+
default='a')
29+
30+
args = parser.parse_args()
31+
32+
if os.path.isfile(args.text):
33+
args.text = open(args.text).read().rstrip()
34+
35+
return args
36+
37+
38+
# --------------------------------------------------
39+
def main():
40+
"""Start things up"""
41+
42+
args = get_args()
43+
text = args.text
44+
vowel = args.vowel
45+
46+
new_text = text.translate(str.maketrans('aeiouAEIOU', vowel * 5 + vowel.upper() * 5));
47+
48+
print(new_text)
49+
50+
51+
# --------------------------------------------------
52+
if __name__ == '__main__':
53+
main()

0 commit comments

Comments
 (0)