File tree Expand file tree Collapse file tree 1 file changed +21
-2
lines changed
Expand file tree Collapse file tree 1 file changed +21
-2
lines changed Original file line number Diff line number Diff line change 11import cowsay
2- import sys
2+ import argparse
33
4- cowsay .cow (" " .join (sys .argv [1 :]))
4+ parser = argparse .ArgumentParser (
5+ prog = "Display items" ,
6+ description = "Display the contents of a file reminiscent of the cat command"
7+ )
8+
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+
12+ args = parser .parse_args ()
13+
14+ animal_entered = args .animal
15+ message_to_say = " " .join (args .message )
16+
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 )
21+ else :
22+ print (f"'{ animal_entered } ' is not a valid animal. please choose from '{ animals [1 :]} '" )
23+ print (f"Try one of: { ', ' .join (animals )} " )
You can’t perform that action at this time.
0 commit comments