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
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
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'.