From 2ebe91f11183d9b332ae5e00611f7e8f03418b91 Mon Sep 17 00:00:00 2001 From: Will Trimble Date: Fri, 11 Oct 2013 14:34:58 -0500 Subject: [PATCH] removed stray non-printing unicode characters W. Trevor King: I dropped everything from the original 64f4940 except for the lessons/thw-testing/exercises.md modification. Conflicts: lessons/thw-numpy/long_exercise.md lessons/thw-python/obj-orientation/exercises/oop.markdown setup/bin/README.md --- lessons/thw-testing/exercises.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lessons/thw-testing/exercises.md b/lessons/thw-testing/exercises.md index fb25fe1..5787268 100644 --- a/lessons/thw-testing/exercises.md +++ b/lessons/thw-testing/exercises.md @@ -3,14 +3,14 @@ asking you to submit your solutions to these exercises and then we will post up solutions at the start of next week. We encourage you to discuss your approaches or solutions on the course forum! -To submit your exercises, please create a `testing` folder in your personal +To submit your exercises, please create a `testing` folder in your personal folder in the course repository. Place all of the code and files for theses exercises in that folder and be sure to check it in. ## Exercise 1: Mileage -The function 'convert_mileage' converts miles per gallon (US style) to liters +The function 'convert_mileage' converts miles per gallon (US style) to liters per 100 km (metric style): ```python @@ -23,12 +23,12 @@ per 100 km (metric style): return litres_per_100_km ``` -Create a subdirectory in your version control directory called `testing`, then -copy this function into a file in that directory called `mileage.py`. Add more -code to that file to repeatedly ask the user for a mileage in miles per gallon, +Create a subdirectory in your version control directory called `testing`, then +copy this function into a file in that directory called `mileage.py`. Add more +code to that file to repeatedly ask the user for a mileage in miles per gallon, and output the mileage in liters per 100 km, until the user enters the string -"`q`". You will need to use the `float()` function to convert from string to a -floating point number. Use the '`if __name__ == "__main__":`' trick to ensure +"`q`". You will need to use the `float()` function to convert from string to a +floating point number. Use the '`if __name__ == "__main__":`' trick to ensure that the module can be imported without executing your testing code. 1. Copy `mileage.py` to create `tryexcept.py` Add a try/except block to the new @@ -44,20 +44,20 @@ to use for invalid input. Create a copy of 'tryexcept.py' called 'raiser.py' that raises this exception; modify the main body of your program to catch it; and add a comment inside the file explaining why you chose the exception you did. (Note: you have to call this file `raiser.py`, not `raise.py` because -'import raise' is an error.  Can you see why?) +'import raise' is an error. (Can you see why?) 3. [According to Google](http://www.google.ca/search?q=20+miles+per+gallon+in+litres+per+100+km&gbv=1), 20 miles per gallon are equivalent to 11.7607292 liters per 100 km. Use these values to write a unit test. Keep in mind that these floating values are subject to truncation and rounding errors. Save the test case in a file called -`test_mileage.py` and run it using the `nosetests` command.  Note: +`test_mileage.py` and run it using the `nosetests` command. ( Note: `test_mileage.py` should use '`from raiser import convert_mileage`' to get the final version of your mileage conversion function. 4. Now add a second test case, for 40 miles per gallon equivalent to 5.88036458 -liters per 100 km and run the tests again.  Unless you have already fixed the -error that was present in the initial function, your test should fail.  Find +liters per 100 km and run the tests again. Unless you have already fixed the +error that was present in the initial function, your test should fail. Find and fix the error; submit your new function in a file called 'final_mileage.py'. -- 2.26.2