From aacddf67c1213392d1b7ff493310d3152fb388f8 Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Sat, 21 Mar 2026 15:02:25 +0000 Subject: [PATCH 1/2] complete implement-cowsay exercise --- .gitignore | 1 + implement-cowsay/cow.py | 27 +++++++++++++++++++++++++++ implement-cowsay/requirements.txt | 1 + 3 files changed, 29 insertions(+) create mode 100644 implement-cowsay/cow.py create mode 100644 implement-cowsay/requirements.txt diff --git a/.gitignore b/.gitignore index 3c3629e64..671215ddc 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +.venv diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 000000000..0cbd01a0e --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,27 @@ +import argparse +import cowsay + +def main(): + # Set up argument parser + parser = argparse.ArgumentParser(description="Make animals say things") + parser.add_argument("message", nargs="+", help="The message to say.") + parser.add_argument( + "--animal", + choices=cowsay.char_names, + default="cow", + help="The animal to be saying things.", + ) + + args = parser.parse_args() + + # Combine the message into a single string + message = " ".join(args.message) + + # Get the animal function dynamically + animal_function = getattr(cowsay, args.animal, cowsay.cow) + + # Print the message using the selected animal + print(animal_function(message)) + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/implement-cowsay/requirements.txt b/implement-cowsay/requirements.txt new file mode 100644 index 000000000..c6b9ffd0e --- /dev/null +++ b/implement-cowsay/requirements.txt @@ -0,0 +1 @@ +cowsay From c2d9fc9b364401a813e4a823b346d8424773f98e Mon Sep 17 00:00:00 2001 From: enjoy15 Date: Thu, 23 Apr 2026 22:27:00 +0100 Subject: [PATCH 2/2] Refactor animal function retrieval and message display in cowsay implementation --- implement-cowsay/cow.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index 0cbd01a0e..4f5d37b69 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -17,11 +17,11 @@ def main(): # Combine the message into a single string message = " ".join(args.message) - # Get the animal function dynamically - animal_function = getattr(cowsay, args.animal, cowsay.cow) + # Get the animal function from the library mapping + animal_function = cowsay.char_funcs[args.animal] - # Print the message using the selected animal - print(animal_function(message)) + # Display the message using the selected animal + animal_function(message) if __name__ == "__main__": main() \ No newline at end of file