https://www.youtube.com/playlist?list=PLhOuww6rJJNM2jtyu3zw3aIeZ8Ov7hSy-
Create a program that will read a CSV -f
or --file
of exercises (default exercises.csv
) and create a Workout of the Day:
$ ./wod.pyExercise Reps------------------ ------Pushups 74Hand-stand pushups 10Squats 29Burpees 33
The program should accept an alternate --file
:
$ ./wod.py -f silly-exercises.csvExercise Reps-------------------- ------Erstwhile Lunges 18Hanging Chads 90Red Barchettas 36Masochistic Eardowns 29
And should reject non-existent file arguments:
$ ./wod.py -f lkjdflkjusage: wod.py [-h] [-f str] [-s int] [-n int] [-e]wod.py: error: argument -f/--file: can't open 'lkjdflkj': [Errno 2] No such file or directory: 'lkjdflkj'
The file structure looks like this:
$ cat exercises.csvexercise,repsBurpees,20-50Situps,40-100Pushups,25-75Squats,20-50Pullups,10-30Hand-stand pushups,5-20Lunges,20-40Plank,30-60Crunches,20-30
The program should accept an -n
or --num
argument to control the number of exercises which are randomly chosen from the input file. The Reps value will be randomly chosen from the given low/high range in the reps column:
$ ./wod.py -n 2Exercise Reps---------- ------Situps 83Pullups 30
The program should accept a -s
or --seed
value for the random seed to ensure reproducibility:
$ ./wod.py -s 1Exercise Reps---------- ------Pushups 56Situps 88Crunches 27Burpees 35
As well as a -e
or --easy
flag to indicate that the reps should be halved:
$ ./wod.py -s 1 -eExercise Reps---------- ------Pushups 28Situps 44Crunches 13Burpees 17
The program should print a usage for the -h
or --help
flags:
$ ./wod.py -husage: 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: exercises.csv) -s int, --seed int Random seed (default: None) -n int, --num int Number of exercises (default: 4) -e, --easy Halve the reps (default: False)
Run the test suite to ensure your program is working correctly:
$ make testpytest -xv test.py============================= test session starts ==============================...collected 8 itemstest.py::test_exists PASSED [ 12%]test.py::test_usage PASSED [ 25%]test.py::test_bad_num PASSED [ 37%]test.py::test_bad_file PASSED [ 50%]test.py::test_seed1 PASSED [ 62%]test.py::test_seed1_easy PASSED [ 75%]test.py::test_seed2_num8 PASSED [ 87%]test.py::test_seed4_num3_input2 PASSED [100%]============================== 8 passed in 0.64s ===============================
The test suite only checks your program using well-formed input files. There are several bad input files provided which are not used by the test but are provided for you to try with your program. These represent several types of real-world problems you might encounter parsing delimited text files.
Reviews
There are no reviews yet.