Write a Python program called wod.py that will create a Workout Of (the) Day (WOD) from a list of exercises provided in CSV format (default wod.csv). Accept a -n|--num_exercises argument (default 4) to determine the sample size from your exercise list. Also accept a -e|--easy flag to indicate that the reps should be cut in half. Finally accept a -s|--seed argument to pass to random.seed for testing purposes. You should use the tabulate module to format the output as expected.
The input file should be comma-separated values with headers for "exercise" and "reps," e.g.:
$ tablify.py wod.csv
+---------------+--------+
| exercise | reps |
|---------------+--------|
| Burpees | 20-50 |
| Situps | 40-100 |
| Pushups | 25-75 |
| Squats | 20-50 |
| Pullups | 10-30 |
| HSPU | 5-20 |
| Lunges | 20-40 |
| Plank | 30-60 |
| Jumprope | 50-100 |
| Jumping Jacks | 25-75 |
| Crunches | 20-30 |
| Dips | 10-30 |
+---------------+--------+
You should use the range of reps to choose a random integer value in that range.
$ ./wod.py -h
usage: wod.py [-h] [-f str] [-s int] [-n int] [-e]
Create Workout Of (the) Day (WOD)
optional arguments:
-h, --help show this help message and exit
-f str, --file str CSV input file of exercises (default: wod.csv)
-s int, --seed int Random seed (default: None)
-n int, --num_exercises int
Number of exercises (default: 4)
-e, --easy Make it easy (default: False)
$ ./wod.py
Exercise Reps
---------- ------
Crunches 26
HSPU 9
Squats 43
Pushups 36
$ ./wod.py -s 1
Exercise Reps
------------- ------
Pushups 32
Jumping Jacks 56
Situps 88
Pullups 24
$ ./wod.py -s 1 -e
Exercise Reps
------------- ------
Pushups 15
Jumping Jacks 27
Situps 44
Pullups 12
$ ./wod.py -f wod2.csv -n 5
Exercise Reps
-------------------- ------
Erstwhile Lunges 9
Existential Earflaps 32
Rock Squats 21
Squatting Chinups 49
Flapping Leg Raises 17
Hints:
- Use the
csvmodule'sDictReaderto read the input CSV files - Break the
repsfield on the-character, coerce the low/high values tointvalues, and then use therandommodule to choose a random integer in that range. Also see if therandommodule can help you sample some exercises. - Read the docs on the
tabulatemodule to figure out to get it to print your data