Skip to content
Closed
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
*/venv
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"cowsay"
]
}
1 change: 1 addition & 0 deletions implement-cowsay/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.venv/
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(
description="Make animals say things")

parser.add_argument(
"message", nargs="+", help="The message to say.")

parser.add_argument(
"--animal",
choices=cowsay.char_names,
help="The animal to be saying things.")

args = parser.parse_args()

message = " ".join(args.message)

animal = args.animal or "cow"

print(getattr(cowsay, animal)(message))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do you need this print() here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, cowsay returns a string rather than printing directly, so print() is needed. I’ll refactor it slightly for readability by separating the function call from the print statement.

Comment thread
LonMcGregor marked this conversation as resolved.
Comment thread
LonMcGregor marked this conversation as resolved.
Empty file.