diff --git a/.gitignore b/.gitignore index 68ca39690..2a4d5f161 100644 --- a/.gitignore +++ b/.gitignore @@ -11,8 +11,7 @@ tex2pdf* .coverage .idea .vscode -02_crowsnest/crowsnest.py -03_picnic/picnic.py +.venv 04_jump_the_five/jump.py 05_howler/howler.py 06_wc/wc.py diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100755 index 000000000..339b161cb --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python3 +""" +Author: RuthlessHelp +Date: 2025-07-21 +File: hello.py +Purpose: A simple script to print "Hello, World!" +""" + +import argparse + + +def def_args(): + """Define command line arguments.""" + parser = argparse.ArgumentParser(description="Say hello.") + parser.add_argument('-n', '--name', metavar='name', + default='World', help='Name to greet') + args = parser.parse_args() + return args + + +def main(): + """Main function to execute the script.""" + args = def_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..d498e9aa2 --- /dev/null +++ b/02_crowsnest/crowsnest.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python3 +""" +Author: RuthlessHelp +Date: 2025-07-21 +File: crowsnest.py +Purpose: A script to greet the captain with a word from the crow's nest. +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """Get command-line arguments""" + + parser = argparse.ArgumentParser( + description='Crow\'s Nest', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('word', + metavar='str', + help='A word argument') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """Make a jazz noise here""" + + args = get_args() + word = args.word + article = 'an' if word[0].lower() in 'aeiou' else 'a' + print(f'Ahoy, Captain, {article} {word} off the larboard bow!') + + +# -------------------------------------------------- +if __name__ == '__main__': + main() diff --git a/03_picnic/picnic.py b/03_picnic/picnic.py new file mode 100755 index 000000000..4b82b75be --- /dev/null +++ b/03_picnic/picnic.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +""" +Author: RuthlessHelp +Date: 2025-07-21 +File: picnic.py +Purpose: A script to manage picnic items +""" + +import argparse + + +# -------------------------------------------------- +def get_args(): + """ + Parse command-line arguments for picnic items + """ + + parser = argparse.ArgumentParser( + description='Picnic items', + formatter_class=argparse.ArgumentDefaultsHelpFormatter) + + parser.add_argument('items', + metavar='items', + nargs='+', + type=str, + help='A list of items to bring') + + parser.add_argument('-s', + '--sorted', + help='A boolean flag', + default=False, + action='store_true') + + return parser.parse_args() + + +# -------------------------------------------------- +def main(): + """ + Main function to handle picnic items + """ + + args = get_args() + if args.sorted: + args.items.sort() + + if len(args.items) == 0: + print('You are not bringing anything.') + elif len(args.items) == 1: + print(f'You are bringing {args.items[0]}.') + elif len(args.items) == 2: + print(f'You are bringing {args.items[0]} and {args.items[1]}.') + else: + last_item = args.items.pop() + print(f'You are bringing {", ".join(args.items)}, and {last_item}.') + + +if __name__ == '__main__': + main()