From 475c940c75a3a233ff4c3ac170c94df8c5ce2bcb Mon Sep 17 00:00:00 2001 From: Fatma Degirmenci Date: Mon, 8 Dec 2025 11:44:50 +0000 Subject: [PATCH 1/2] implement cowsay --- implement-cowsay/.gitignore | 1 + implement-cowsay/cow.py | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 implement-cowsay/.gitignore create mode 100644 implement-cowsay/cow.py diff --git a/implement-cowsay/.gitignore b/implement-cowsay/.gitignore new file mode 100644 index 00000000..21d0b898 --- /dev/null +++ b/implement-cowsay/.gitignore @@ -0,0 +1 @@ +.venv/ diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 00000000..216a9409 --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,17 @@ +import argparse +import cowsay + + +parser = argparse.ArgumentParser(description="implement Cowsay command") +parser.add_argument("text", help="Text to be displayed") +parser.add_argument("--animal", help="Animal to say the text", default="cow") +args = parser.parse_args() + +animals = cowsay.char_names +animal = args.animal.lower() +if animal not in animals: + print(f"Invalid animal. Supported animals are: {', '.join(animals)}") + exit(1) +cowsay.char_funcs[animal](args.text) + + From 02a58e183d759ba47946606588f11f9d49ffbe3f Mon Sep 17 00:00:00 2001 From: Fatma Degirmenci Date: Tue, 20 Jan 2026 11:42:56 +0000 Subject: [PATCH 2/2] fix: handle multi word text and display animals in help --- implement-cowsay/cow.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py index 216a9409..c6f868be 100644 --- a/implement-cowsay/cow.py +++ b/implement-cowsay/cow.py @@ -1,17 +1,16 @@ import argparse import cowsay +animals = list(cowsay.char_funcs.keys()) parser = argparse.ArgumentParser(description="implement Cowsay command") -parser.add_argument("text", help="Text to be displayed") -parser.add_argument("--animal", help="Animal to say the text", default="cow") +parser.add_argument("text",nargs="+" ,help="Text to be displayed") +parser.add_argument("--animal", help=f"Animal to say the text (choices: {', '.join(animals)})", default="cow",choices=animals) args = parser.parse_args() -animals = cowsay.char_names -animal = args.animal.lower() -if animal not in animals: - print(f"Invalid animal. Supported animals are: {', '.join(animals)}") - exit(1) -cowsay.char_funcs[animal](args.text) +text = " ".join(args.text) +animal = args.animal + +cowsay.char_funcs[animal](text)