Skip to content

Commit 7d1e4b7

Browse files
cowsay implementation complete, code cleaned up
1 parent 62bd86e commit 7d1e4b7

1 file changed

Lines changed: 6 additions & 12 deletions

File tree

implement-cowsay/cow.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,26 @@
11
import cowsay
22
import argparse
33

4+
# Get dynamic list of animals from the cowsay library
45
animals = cowsay.char_names
56

67
parser = argparse.ArgumentParser(
78
prog="cowsay",
89
description="Make animals say things"
910
)
1011

11-
parser.add_argument("-a", "--animal", choices=animals, help="The animal to be saying things.")
12+
parser.add_argument("--animal", choices=animals, help="The animal to be saying things.")
1213
parser.add_argument("message", nargs="+", help="The message to say.")
1314

1415
args = parser.parse_args()
1516

17+
# Join all message words into a single string
1618
message = " ".join(args.message)
1719

18-
print(args)
1920

2021
if args.animal:
21-
# cowsay[args.animal](message)
22-
print(cowsay.get_output_string(args.animal, message))
23-
# print('hi')
22+
cowsay.char_funcs[args.animal](message)
2423
else:
25-
# print(cowsay.get_output_string('cow', 'Hello World'))
26-
cowsay.cow(message) # if no animal is provided, use default
24+
# if no animal is provided, use default
25+
cowsay.cow(message)
2726

28-
29-
30-
print(animals)
31-
32-

0 commit comments

Comments
 (0)