Skip to content

Commit 9c2819e

Browse files
committed
cowsay review
1 parent 70d3155 commit 9c2819e

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

implement-cowsay/cow.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import argparse
2+
import cowsay
3+
4+
def main():
5+
# List of available animals (provided by the package)
6+
animals = cowsay.char_names
7+
8+
parser = argparse.ArgumentParser(
9+
prog="cowsay",
10+
description="Make animals say things"
11+
)
12+
13+
parser.add_argument(
14+
"message",
15+
nargs="+",
16+
help="The message to say."
17+
)
18+
19+
parser.add_argument(
20+
"--animal",
21+
choices=animals,
22+
default="cow",
23+
help="The animal to be saying things."
24+
)
25+
26+
args = parser.parse_args()
27+
28+
message = " ".join(args.message)
29+
30+
# Dynamically call the function for the chosen animal
31+
animal_func = getattr(cowsay, args.animal)
32+
print(animal_func(message))
33+
34+
35+
if __name__ == "__main__":
36+
main()

0 commit comments

Comments
 (0)