Skip to content

Commit aacddf6

Browse files
committed
complete implement-cowsay exercise
1 parent b5089a2 commit aacddf6

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
.venv

implement-cowsay/cow.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import argparse
2+
import cowsay
3+
4+
def main():
5+
# Set up argument parser
6+
parser = argparse.ArgumentParser(description="Make animals say things")
7+
parser.add_argument("message", nargs="+", help="The message to say.")
8+
parser.add_argument(
9+
"--animal",
10+
choices=cowsay.char_names,
11+
default="cow",
12+
help="The animal to be saying things.",
13+
)
14+
15+
args = parser.parse_args()
16+
17+
# Combine the message into a single string
18+
message = " ".join(args.message)
19+
20+
# Get the animal function dynamically
21+
animal_function = getattr(cowsay, args.animal, cowsay.cow)
22+
23+
# Print the message using the selected animal
24+
print(animal_function(message))
25+
26+
if __name__ == "__main__":
27+
main()

implement-cowsay/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
cowsay

0 commit comments

Comments
 (0)