Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions implement-cowsay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv/
__pycache__/
21 changes: 21 additions & 0 deletions implement-cowsay/cow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import argparse
import cowsay

parser = argparse.ArgumentParser(prog="cow.py",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The README's expected help output starts with usage: cowsay …, but prog="cow.py" produces usage: cow.py

description="Print a message using a cowsay animal")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description="Print a message using a cowsay animal" - README expects Make animals say things. Worth matching exactly since the task explicitly shows the expected --help output.


parser.add_argument("message")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

parser.add_argument("message") only consumes one positional, so python3 cow.py Grass, delicious. (the very first required example in the README) errors with "unrecognized arguments: delicious.".

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a help="The message to say." to the message positional so it shows up in --help (the README's expected
output includes it).

parser.add_argument("-a",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try running python3 cow.py --animal fish hello and compare the error to the one shown in the README -they're not the same, and --help is also missing the {beavis,cheese,...,tux} choices list that the README's expected help output includes. Does argparse already offer a built-in way to declare "this argument must be one of these values" that would handle both the error formatting and the help text for you? If you find it, what could the manual if args.animal not in animal_names block become?

"--animal",
default="cow",
help="Animal to use for the speech bubble.")

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Help string for --animal is "Animal to use for the speech bubble." - README expects "The animal to be saying
things.".


args = parser.parse_args()

animal_names = cowsay.char_names

if args.animal not in animal_names:
parser.error("The specified animal is not found in the cowsay animal list.")

animal_function = getattr(cowsay, args.animal)
animal_function(args.message)
1 change: 1 addition & 0 deletions implement-cowsay/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cowsay
Loading