Create a project folder username_a04
. Place all your tasks
python files(t01.py
, t02.py
,t03.py
)
and the testing file testing.txt
inside this folder. Upon
completing your tasks, export your projrct folder to username_a04.zip
file, validate it, and submit it to the dropbox by the due date.
Write and test the following function:
def day_of_week(day_number):
Add the function to a Python module named functions.py
.
Test it from .
day_of_week
takes an integer parameter and returns a
string representing the corresponding day of the week, where 1 =
"Sunday", 2 = "Monday", up to 7 = "Saturday". The function returns
"Error" if the parameter is a number outside the range of 1 through 7.
Assume that the parameter is an integer.
Provide the function docstring (documentation) following the CP104 style.
The function does not ask for input and does no printing - that is done by your test program.
Sample executions:
day_of_week(1) -> "Sunday" day_of_week(7) -> "Saturday" day_of_week(99) -> "Error"
Test the function three times.
Partial testing:
Write and test the following function:
def product_largest(v1, v2, v3):
"""
-------------------------------------------------------
Returns the product of the two largest values of
v1, v2, and v3.
Use: product = product_largest(v1, v2, v3)
-------------------------------------------------------
Parameters:
v1 - a number (float)
v2 - a number (float)
v3 - a number (float)
Returns:
product - the product of the two largest values of
v1, v2, and v3 (float)
------------------------------------------------------
"""
Add the function to a Python module named functions.py
.
Test it from .
The function does not ask for input and does no printing - that is done by your test program.
Sample executions:
product_largest(-8, 12, 20) -> 240 product_largest(-5, 0, 9) -> 0
Test the function with three different sets of parameters.
Partial testing:
Write and test the following function:
def rgb_mix(rgb1, rgb2):
"""
-------------------------------------------------------
Determines the secondary colour from mixing two primary
RGB (Red, Green, Blue) colours. The order of the colours
is *not* significant.
Returns "Error" if any of the colour parameter(s) are invalid.
"red" + "blue": "fuchsia"
"red" + "green": "yellow"
"green" + "blue": "aqua"
"red" + "red": "red"
"blue" + "blue": "blue"
"green" + "green": "green"
Use: colour = rgb_mix(rgb1, rgb2)
-------------------------------------------------------
Parameters:
rgb1 - a primary RGB colour (str)
rgb2 - a primary RGB colour (str)
Returns:
colour - a secondary RGB colour (str)
-------------------------------------------------------
"""
Add the function to a Python module named functions.py
.
Test it from .
The function does not ask for input and does no printing - that is done by your test program.
Sample executions:
rgb_mix("red", "green") -> "yellow" rgb_mix("green", "red") -> "yellow" rgb_mix("blue", "kipney") -> "Error"
Test the function with three different sets of parameters.
Partial testing:
Partial testing of functions.py:
Partial testing of testing.txt: