Skip to content

Commit e98733b

Browse files
committed
implement cowsay task
1 parent b5089a2 commit e98733b

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

implement-cowsay/cow.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import argparse
2+
from email import message
3+
import cowsay
4+
5+
def main():
6+
#Get the list of animals from cowsay library
7+
animals = sorted(cowsay.char_names)
8+
parser = argparse.ArgumentParser(
9+
prog="cowsay",
10+
description= "Make animal say things"
11+
)
12+
13+
parser.add_argument(
14+
"--animal",
15+
choices=animals,
16+
default="cow",
17+
help="The animal to say the message."
18+
)
19+
parser.add_argument(
20+
"message",
21+
nargs="+",
22+
help="The message to be said by the animal."
23+
)
24+
25+
args = parser.parse_args()
26+
# Join message list into a single string
27+
text = " ".join(args.message)
28+
# Default animal is "cow" if not specified
29+
print(cowsay.get_output_string(args.animal, text))
30+
31+
if __name__ == "__main__":
32+
main()

0 commit comments

Comments
 (0)