From fd13064b432de7c5c8894fcf6c09d3fa3a2dd894 Mon Sep 17 00:00:00 2001 From: "jianjun.feng" Date: Fri, 27 Aug 2021 21:26:22 -0500 Subject: [PATCH 1/2] done --- 02_crowsnest/test.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/02_crowsnest/test.py b/02_crowsnest/test.py index d4e25c6c7..6cba6677c 100755 --- a/02_crowsnest/test.py +++ b/02_crowsnest/test.py @@ -47,7 +47,7 @@ def test_consonant_upper(): for word in consonant_words: out = getoutput(f'{prg} {word.title()}') - assert out.strip() == template.format('a', word.title()) + assert out.strip() == template.format('A', word.title()) # -------------------------------------------------- @@ -65,4 +65,19 @@ def test_vowel_upper(): for word in vowel_words: out = getoutput(f'{prg} {word.upper()}') - assert out.strip() == template.format('an', word.upper()) + assert out.strip() == template.format('An', word.upper()) + +#------------------------------------------------------- +def test_match_upper(): + """octopus -> an Octopus""" + + for word in vowel_words: + out = getoutput(f'{prg} {word.upper()}') + assert out.strip() == template.format('An', word.upper()) +#------------------------------------------------------- +def test_match_lower(): + """octopus -> an Octopus""" + + for word in vowel_words: + out = getoutput(f'{prg} {word.lower()}') + assert out.strip() == template.format('an', word) From 48f652d09f61aa121d9d5c52d0b1401673d2f7e9 Mon Sep 17 00:00:00 2001 From: "jianjun.feng" Date: Fri, 27 Aug 2021 23:19:19 -0500 Subject: [PATCH 2/2] done --- 02_crowsnest/crowsnest.py | 82 +++++++++++++++++++++++++++++++++++++++ 03_picnic/picnic.py | 56 ++++++++++++++++++++++++++ 2 files changed, 138 insertions(+) create mode 100755 02_crowsnest/crowsnest.py create mode 100755 03_picnic/picnic.py diff --git a/02_crowsnest/crowsnest.py b/02_crowsnest/crowsnest.py new file mode 100755 index 000000000..7b0776a59 --- /dev/null +++ b/02_crowsnest/crowsnest.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python3 +""" +Author : jf440947 +Date : 2021-08-27 +Purpose: Rock the Casbah +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Crows Nest', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('word', + metavar='word', + help='A positional argument') + + parser.add_argument('-s', + '--side', + help='specify which side of the boat', + metavar='str', + type=str, + default='larboard') + +# parser.add_argument('-i', +# '--int', +# help='A named integer argument', +# metavar='int', +# type=int, +# default=0) +# +# parser.add_argument('-f', +# '--file', +# help='A readable file', +# metavar='FILE', +# type=argparse.FileType('rt'), +# default=None) +# + parser.add_argument('-o', + '--on', + help='A boolean flag', + action='store_true') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + str_arg = args.side +# int_arg = args.int +# file_arg = args.file + flag_arg = args.on + pos_arg = args.word + + print(f'str_arg = "{str_arg}"') +# print(f'int_arg = "{int_arg}"') +# print('file_arg = "{}"'.format(file_arg.name if file_arg else '')) + print(f'flag_arg = "{flag_arg}"') + if pos_arg[0] in "AEIOU": + article='An' + elif pos_arg[0] in "aeiou": + article='an' + elif pos_arg[0].islower(): + article='a' + else: + article='A' + side = str_arg + print(f'Ahoy, Captain, {article} {pos_arg} off the {side} bow!') +# print(dir(args)) +# + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/03_picnic/picnic.py b/03_picnic/picnic.py new file mode 100755 index 000000000..fb449fd03 --- /dev/null +++ b/03_picnic/picnic.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +""" +Author : jf440947 +Date : 2021-08-27 +Purpose: Rock the Casbah +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Picnic game', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('items', + metavar='items', + nargs='+', + help='Items to bring') + parser.add_argument('-s', + '--sorted', + help='sort the list first', + action='store_true') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here """ + + args = get_args() + should_sort = args.sorted + items = args.items + if should_sort: + items=sorted(items) + cnt = len(items) + items_str='' + if cnt ==1: + items_str=items[0] + elif cnt==2: + items_str=f"{items[0]} and {items[1]}" + elif cnt > 2: + for i in range(cnt-1): + items_str += f"{items[i]}, " + items_str=f"{items_str}and {items[cnt-1]}" + + print(f"You are bringing {items_str}.") + + +# -------------------------------------------------- +if __name__ == '__main__': + main()