diff --git a/.gitignore b/.gitignore index 68ca39690..a12e7b2dd 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,7 @@ tex2pdf* .coverage .idea .vscode -02_crowsnest/crowsnest.py +.python-version 03_picnic/picnic.py 04_jump_the_five/jump.py 05_howler/howler.py diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100755 index 000000000..3cb640d2f --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,30 @@ +#! /usr/bin/env python3 +""" +Author: Robert Mikolajczyk +email: ronert1674@gmail.com +Purpose: Say hello +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + parser = argparse.ArgumentParser(description="Say hello") + parser.add_argument( + "-n", "--name", metavar="name", default="World", help="Name to greet" + ) + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + args = get_args() + print("Hello, " + args.name + "!") + + +# -------------------------------------------------- +if __name__ == "__main__": + main() diff --git a/01_hello/hello2.py b/01_hello/hello2.py new file mode 100755 index 000000000..5b4896dca --- /dev/null +++ b/01_hello/hello2.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python3 +""" +Author : robertmikolajczyk +Date : 2025-05-11 +Purpose: Rock the Casbah +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Rock the Casbah', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('positional', + metavar='str', + help='A positional argument') + + parser.add_argument('-a', + '--arg', + help='A named string argument', + metavar='str', + type=str, + default='') + + 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.arg + int_arg = args.int + file_arg = args.file + flag_arg = args.on + pos_arg = args.positional + + 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}"') + print(f'positional = "{pos_arg}"') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/02_crowsnest/crowsnest.py b/02_crowsnest/crowsnest.py new file mode 100755 index 000000000..6bd7151ac --- /dev/null +++ b/02_crowsnest/crowsnest.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python3 +""" +Author : robertmikolajczyk +Date : 2025-05-12 +Purpose: Crow's Nest +""" + +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="word", + help="A word") + + parser.add_argument('--starboard', + help='A right side of the board', + action='store_true') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + word = args.word + side = args.starboard + + sideboard = "starboard" if side else "larboard" + article = "an" if word[0].lower() in "aeiou" else "a" + print(f"Ahoy, Captain, {article} {word} off the {sideboard} bow!") + + +# -------------------------------------------------- +if __name__ == "__main__": + main()