From 09381a18eb95e43ac5bf156e8fe98cc55f8e55c8 Mon Sep 17 00:00:00 2001 From: Stephen Ritchie Date: Mon, 21 Jul 2025 10:53:35 -0400 Subject: [PATCH 1/5] Exclude the .venv folders --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 68ca39690..2fd75793f 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ tex2pdf* .coverage .idea .vscode +.venv 02_crowsnest/crowsnest.py 03_picnic/picnic.py 04_jump_the_five/jump.py From 56559812235d8b8bfa98d322b91700fc131e7fda Mon Sep 17 00:00:00 2001 From: Stephen Ritchie Date: Mon, 21 Jul 2025 11:21:04 -0400 Subject: [PATCH 2/5] Tiny Python Projects chapter 01 --- 01_hello/hello.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 01_hello/hello.py diff --git a/01_hello/hello.py b/01_hello/hello.py new file mode 100755 index 000000000..ab63aeb40 --- /dev/null +++ b/01_hello/hello.py @@ -0,0 +1,28 @@ +#! /usr/bin/env python3 +""" +Author: RuthlessHelp +Date: 2023-10-01 +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() From dc78b6813523538bfd6a2a7e220987506fe86135 Mon Sep 17 00:00:00 2001 From: Stephen Ritchie Date: Mon, 21 Jul 2025 13:13:44 -0400 Subject: [PATCH 3/5] Add my solution for Crowsnest --- .gitignore | 1 - 02_crowsnest/crowsnest.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) create mode 100755 02_crowsnest/crowsnest.py diff --git a/.gitignore b/.gitignore index 2fd75793f..af6939794 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ tex2pdf* .idea .vscode .venv -02_crowsnest/crowsnest.py 03_picnic/picnic.py 04_jump_the_five/jump.py 05_howler/howler.py 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() From d7b6a379059009110e3ee58a638ae57fb27967b4 Mon Sep 17 00:00:00 2001 From: Stephen Ritchie Date: Mon, 21 Jul 2025 14:07:19 -0400 Subject: [PATCH 4/5] Fix typo on date --- 01_hello/hello.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/01_hello/hello.py b/01_hello/hello.py index ab63aeb40..339b161cb 100755 --- a/01_hello/hello.py +++ b/01_hello/hello.py @@ -1,7 +1,7 @@ #! /usr/bin/env python3 """ Author: RuthlessHelp -Date: 2023-10-01 +Date: 2025-07-21 File: hello.py Purpose: A simple script to print "Hello, World!" """ From 06c637b0bab2162b58bea747b8a3e48a80770fcf Mon Sep 17 00:00:00 2001 From: Stephen Ritchie Date: Mon, 21 Jul 2025 14:09:26 -0400 Subject: [PATCH 5/5] Add my solution for Picnic --- .gitignore | 1 - 03_picnic/picnic.py | 59 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100755 03_picnic/picnic.py diff --git a/.gitignore b/.gitignore index af6939794..2a4d5f161 100644 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,6 @@ tex2pdf* .idea .vscode .venv -03_picnic/picnic.py 04_jump_the_five/jump.py 05_howler/howler.py 06_wc/wc.py 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()