Skip to content

Commit 4c2f815

Browse files
committed
new version
1 parent eaf9e6e commit 4c2f815

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!/usr/bin/env python3
2+
"""Apples and Bananas"""
3+
4+
import argparse
5+
import os
6+
import re
7+
8+
9+
# --------------------------------------------------
10+
def get_args():
11+
"""get command-line arguments"""
12+
13+
parser = argparse.ArgumentParser(
14+
description='Apples and bananas',
15+
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
16+
17+
parser.add_argument('text', metavar='text', help='Input text or file')
18+
19+
parser.add_argument('-v',
20+
'--vowel',
21+
help='The vowel to substitute',
22+
metavar='vowel',
23+
type=str,
24+
default='a',
25+
choices=list('aeiou'))
26+
27+
args = parser.parse_args()
28+
29+
if os.path.isfile(args.text):
30+
args.text = open(args.text).read().rstrip()
31+
32+
return args
33+
34+
35+
# --------------------------------------------------
36+
def main():
37+
"""Make a jazz noise here"""
38+
39+
args = get_args()
40+
print(''.join([new_char(c, args.vowel) for c in args.text]))
41+
42+
43+
# --------------------------------------------------
44+
def new_char(char, vowel):
45+
"""Return the given vowel if a char is a vowel else the char"""
46+
47+
return vowel if char in 'aeiou' else \
48+
vowel.upper() if char in 'AEIOU' else char
49+
50+
51+
# --------------------------------------------------
52+
if __name__ == '__main__':
53+
main()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy