Skip to content

Commit c4c0576

Browse files
committed
feat: Complete the cowsay exercise.
1 parent 75d5ca4 commit c4c0576

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

implement-cowsay/cow.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import cowsay
2+
import argparse
3+
4+
# 1. Fetch the animals from the library
5+
list_of_animals = cowsay.char_names
6+
7+
# 2. Setup the Parser, I'm building a program cowsay that to do(description).
8+
parse = argparse.ArgumentParser(prog='cowsay', description='make animals say things')
9+
parse.add_argument('message', nargs='+', help='The message to say')
10+
11+
parse.add_argument('--animal', choices=list_of_animals, default='cow', help='The animal to use')
12+
13+
args = parse.parse_args()
14+
15+
# Combining the words into a single string
16+
message_text = " ".join(args.message)
17+
18+
# we call the draw_function and we use getattr because args.animal is a string, and we need a function instead.
19+
draw_function = getattr(cowsay, args.animal)
20+
21+
# 4. call and execute.
22+
draw_function(message_text)

implement-cowsay/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cowsay==6.1

0 commit comments

Comments
 (0)