Skip to content

Commit f7ae788

Browse files
committed
These are the programs for the cow-say project
1 parent 4188887 commit f7ae788

File tree

4 files changed

+18
-12
lines changed

4 files changed

+18
-12
lines changed
Binary file not shown.
Binary file not shown.
Binary file not shown.

implement-cowsay/cow_script.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,29 @@
11
import cowsay
22
import argparse
33

4+
animals = [a for a in dir(cowsay) if callable(getattr(cowsay, a)) and not a.startswith("_")]
5+
46
parser = argparse.ArgumentParser(
5-
prog="Display items",
6-
description="Display the contents of a file reminiscent of the cat command"
7+
prog="cowsay",
8+
description="Make animals say things"
79
)
810

9-
parser.add_argument("--animal", help="Gives the user the option of adding the animal")
10-
parser.add_argument("message", nargs="+", help="The message the animal needs to say.")
11+
parser.add_argument(
12+
"--animal",
13+
choices=animals,
14+
help="The animal to be saying things."
15+
)
1116

12-
args = parser.parse_args()
17+
parser.add_argument(
18+
"message",
19+
nargs="+",
20+
help="The message to say."
21+
)
1322

14-
animal_entered = args.animal
23+
args = parser.parse_args()
1524
message_to_say = " ".join(args.message)
1625

17-
animals = [animal for animal in dir(cowsay) if callable(getattr(cowsay, animal))]
18-
19-
if animal_entered in animals:
20-
getattr(cowsay, animal_entered)(message_to_say)
26+
if args.animal:
27+
getattr(cowsay, args.animal)(message_to_say)
2128
else:
22-
print(f"'{animal_entered}' is not a valid animal. please choose from '{animals[1:]}'")
23-
print(f"Try one of: {', '.join(animals)}")
29+
cowsay.cow(message_to_say)

0 commit comments

Comments
 (0)