File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import cowsay
22import argparse
33
4+ # Get dynamic list of animals from the cowsay library
45animals = cowsay .char_names
56
67parser = 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." )
1213parser .add_argument ("message" , nargs = "+" , help = "The message to say." )
1314
1415args = parser .parse_args ()
1516
17+ # Join all message words into a single string
1618message = " " .join (args .message )
1719
18- print (args )
1920
2021if 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 )
2423else :
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-
You can’t perform that action at this time.
0 commit comments