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
36 changes: 36 additions & 0 deletions implement-cowsay/cow.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import cowsay
import argparse

# give a list of supported animal from cowsay
list_of_choices = cowsay.char_names


# to set argument parser
parser = argparse.ArgumentParser(
prog="cowsay",
description="Make animals say things",
)

# to pass optional flag with restricted choice :--animal
parser.add_argument(
"--animal",
choices=list_of_choices,
default="cow",
help="The animal to be saying things."
)

# to add positional argument
parser.add_argument(
"message",
nargs="*",
default="",
help="message to say")

# To parse command line input
args = parser.parse_args()

message_text = " ".join(args.message)

# to print the result with selected element
print(cowsay.get_output_string(str(args.animal), message_text))

Choose a reason for hiding this comment

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

Nit: I believe it is string by default so you don't have to case. No need to update though :)


Binary file added implement-cowsay/requirements.txt
Binary file not shown.