Skip to content

Commit dc44337

Browse files
committed
cowsay task
1 parent 4350f48 commit dc44337

2 files changed

Lines changed: 29 additions & 0 deletions

File tree

implement-cowsay/cow.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import cowsay
2+
import sys
3+
4+
5+
def main():
6+
animal = ""
7+
args = sys.argv[1:]
8+
if len(args) == 0:
9+
print("error: no arguments provided.")
10+
return
11+
if args[0] == "--animal" and len(args) > 1:
12+
animal = args[1]
13+
elif args[0] != "--animal":
14+
animal = "cow"
15+
message = ""
16+
for i in range(2,len(args)):
17+
message += args[i]
18+
19+
try:
20+
getattr(cowsay, animal)(message)
21+
except Exception as e:
22+
if animal == "":
23+
print("error: argument --animal: invalid choice: empty string, choose from 'beavis', 'cheese', 'cow', 'daemon', 'dragon', 'fox', 'ghostbusters', 'kitty', 'meow', 'miki', 'milk', 'octopus', 'pig', 'stegosaurus', 'stimpy', 'trex', 'turkey', 'turtle', 'tux'")
24+
else:
25+
print("error: argument --animal: invalid choice: " + animal + ", choose from 'beavis', 'cheese', 'cow', 'daemon', 'dragon', 'fox', 'ghostbusters', 'kitty', 'meow', 'miki', 'milk', 'octopus', 'pig', 'stegosaurus', 'stimpy', 'trex', 'turkey', 'turtle', 'tux'")
26+
27+
if __name__ == "__main__":
28+
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)