Exercise 2
Exercise 2
This week, we’re working with functions and the design recipe. Your code will be auto-marked, so we won’t
have any way of knowing whether you actually followed the recipe, but a) if you decide not to follow it, you’re
only harming yourself, b) your TAs will not help you with step n of the recipe if you haven’t completed step
n − 1, and c) we reserve the right to randomly check your commenting and design on any exercise with no
prior warning.
For this exercise, you must add 4 functions to the file ex2.py1 . (As always, all file and function names must
be exactly as described in this handout). I’ve left some global variables for you to use in your calculations
at the top of the file, feel free to play around with them, (you should be using these in your calculations),
but return them to their original values before submitting.
1 Percentage
Complete a function called percentage, which takes as its parameters two floats 2 , and returns the a number
representing the first parameter as a percentage of the second parameter. We’ve provided you with the first
few steps of the Design Recipe to get you started.
2 Term Mark
Write a function called term work mark, which calculates your term mark (as a contribution to your final
grade) given your marks on all of the coursework components). Using the default weights this will return a
maximum result of 55 (since the exam is worth 45% of your final grade):
In the starter code provided in ex2.py, there are already several global variables that you will need to
compute this score. The contribution of each piece of coursework is computed as:
mark−you−received
maximum−mark
∗ weight
Your coursework mark is the sum of these component contributions. An example output is given below:
in any way
2 remember, an int is just a special type of a float
3 I’m not guaranteeing that these numbers will be correct for the real course, that’s why I’ve left the variables there for you
to change.
1
Hint:
Rather than writing the same computation over and over, you can make your life easier by using a helper
function... perhaps some nice person may have left a useful function in the file before uploading it...
3 Final Mark
Write a function called final mark, which performs a similar calculation to term work mark, but takes an
additional parameter, your final exam mark (be default, out of 100), and returns your final mark for the
term out of 100.
An example output is given below:
Hint:
Be lazy! If you use the other functions you’ve written, this shouldn’t take more than 3-4 lines of code.
Hint:
See hint for the previous section. 3-4 lines of code should be plenty. Don’t do more work than you need to.