From d08c756c870d8bad82a5c019d862b184889ee839 Mon Sep 17 00:00:00 2001 From: nadika Date: Fri, 21 Mar 2025 18:32:32 +0000 Subject: [PATCH 1/3] Create virtual environment, import modules, edit .gitignore --- implement-cowsay/cow.py | 4 ++++ implement-cowsay/requirements.txt | 1 + 2 files changed, 5 insertions(+) create mode 100644 implement-cowsay/cow.py create mode 100644 implement-cowsay/requirements.txt diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 0000000..46dbaf1 --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,4 @@ +import cowsay +import sys + +cowsay.cow(" ".join(sys.argv[1:])) \ No newline at end of file diff --git a/implement-cowsay/requirements.txt b/implement-cowsay/requirements.txt new file mode 100644 index 0000000..c6b9ffd --- /dev/null +++ b/implement-cowsay/requirements.txt @@ -0,0 +1 @@ +cowsay From 54de3a77bfadac0bfce63fe6fa31d2dcf9eee36b Mon Sep 17 00:00:00 2001 From: nadika Date: Fri, 21 Mar 2025 20:58:38 +0000 Subject: [PATCH 2/3] Implement cowsay functionality to display correct animal, program description, help message --- implement-cowsay/cow.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index 46dbaf1..9ad89cf 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -1,4 +1,27 @@ +# To handle command-line arguments +import argparse +# To use cowsay functionality import cowsay -import sys -cowsay.cow(" ".join(sys.argv[1:])) \ No newline at end of file +# Set up the argument parser +parser = argparse.ArgumentParser(prog="cowsay", description="Make animals say things") + +# Add agruments to specify animal and message. + +# --animal - option specifies the animal to use. +# type=str - type of argument is string. +# choices=list(cowsay.CHARS.keys()) - limits the animal choices to those available in cowsay. +# default='cow' - If no animal is specified, it will default to 'cow'. +# help="The..." - message will be shown when user type '--help' +parser.add_argument('--animal', type=str, choices=list(cowsay.CHARS.keys()), default='cow', help="The animal to be saying things.") +# message - The text that the animal will say +# nargs='+' - accept more than 1 word as input +parser.add_argument('message', type=str, nargs='+', help="The message to say.") + +# Parse the arguments +args = parser.parse_args() + +# Dynamically retrieves a function from the cowsay module based on the user's input. +animal_say_func = getattr(cowsay, args.animal) +# Join words into a string and pass the message to the animal_say_func. +animal_say_func(" ".join(args.message)) From 349a54315a862b2e6b5864dd28e51afbca4de744 Mon Sep 17 00:00:00 2001 From: nadika Date: Fri, 21 Mar 2025 21:00:43 +0000 Subject: [PATCH 3/3] Add .venv to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 3c3629e..0e0052f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ node_modules + +.venv/