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

Skip to content

Commit 03668b3

Browse files
author
Gabriel Soares Martins
committed
Finished chapter 8
1 parent 4991556 commit 03668b3

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

08_apples_and_bananas/apples.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Author : gmartins <gmartins@localhost>
4+
Date : 2025-01-13
5+
Purpose: Rock the Casbah
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+
metavar='vowel',
25+
help='Vowel to change',
26+
default='a',
27+
choices=list('aieou'),
28+
type=str)
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+
"""Make a jazz noise here"""
41+
42+
args = get_args()
43+
44+
S = args.text
45+
for vowel_t in 'aeiouAEIOU':
46+
to_char = args.vowel
47+
if vowel_t.isupper():
48+
to_char = to_char.upper()
49+
S = S.replace(vowel_t, to_char)
50+
print(f'{S}')
51+
52+
53+
# --------------------------------------------------
54+
if __name__ == '__main__':
55+
main()

0 commit comments

Comments
 (0)