diff --git a/implement-cowsay/cow.py b/implement-cowsay/cow.py new file mode 100644 index 00000000..19ef2711 --- /dev/null +++ b/implement-cowsay/cow.py @@ -0,0 +1,36 @@ +import cowsay +import argparse + +# give a list of supported animal from cowsay +list_of_choices = cowsay.char_names + + +# to set argument parser +parser = argparse.ArgumentParser( + prog="cowsay", + description="Make animals say things", +) + +# to pass optional flag with restricted choice :--animal +parser.add_argument( + "--animal", + choices=list_of_choices, + default="cow", + help="The animal to be saying things." +) + +# to add positional argument +parser.add_argument( + "message", + nargs="*", + default="", + help="message to say") + +# To parse command line input +args = parser.parse_args() + +message_text = " ".join(args.message) + +# to print the result with selected element +print(cowsay.get_output_string(str(args.animal), message_text)) + diff --git a/implement-cowsay/requirements.txt b/implement-cowsay/requirements.txt new file mode 100644 index 00000000..1f8ead58 Binary files /dev/null and b/implement-cowsay/requirements.txt differ