diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100755 index 000000000..dc53f6598 --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,19 @@ +#!/usr/bin/env python3 +# Purpose: Say hello + +import argparse + + +def get_args(): + parser = argparse.ArgumentParser(description='Say hello') + parser.add_argument('-n', '--name', help='Name to greet', default='World') + return parser.parse_args() + + +def main(): + args = get_args() + print(f'Hello, {args.name}!') + + +if __name__ == '__main__': + main() diff --git a/02_crowsnest/crowsnest.py b/02_crowsnest/crowsnest.py new file mode 100755 index 000000000..7edba7fc9 --- /dev/null +++ b/02_crowsnest/crowsnest.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +""" +Author : George Studenko +Date : 09-apr-2020 +Purpose: Crow's Nest -- choose the correct article +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Crow''s Nest -- choose the correct article', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('word', + metavar='str', + help='A word') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Start the program""" + + args = get_args() + word = args.word + print_message(word) + + +def print_message(word): + article = get_article(word) + print(f'Ahoy, Captain, {article} {word} off the larboard bow!') + + +def get_article(word): + article = 'a' + if word[0].lower() in 'aeiou': + article = 'an' + return article + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/template/template.py b/template/template.py index 225dea9c4..4b61d8221 100755 --- a/template/template.py +++ b/template/template.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 """ -Author : Me -Date : today -Purpose: Rock the Casbah +Author : George Studenko +Date : Add date +Purpose: Describe this """ import argparse @@ -13,7 +13,7 @@ def get_args(): """Get command-line arguments""" parser = argparse.ArgumentParser( - description='Rock the Casbah', + description='This program purpose is to...', formatter_class=argparse.ArgumentDefaultsHelpFormatter) parser.add_argument('positional',