Skip to content

Commit b90ef41

Browse files
committed
validation using argparse
1 parent dc469dd commit b90ef41

1 file changed

Lines changed: 2 additions & 10 deletions

File tree

implement-cowsay/main.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,5 @@
88
parser.add_argument('message', type=str, help= 'please enter a message')
99
arg = parser.parse_args()
1010

11-
valid_animals = cowsay.char_names
12-
13-
if arg.animal in valid_animals:
14-
animal_func = getattr(cowsay, arg.animal)
15-
print(animal_func(arg.message))
16-
17-
else:
18-
print(f"Error: '{arg.animal}' is not a valid animal.")
19-
print("Valid animals are:", ", ".join(valid_animals))
20-
sys.exit(1)
11+
animal_func = getattr(cowsay, arg.animal)
12+
print(animal_func(arg.message))

0 commit comments

Comments
 (0)