Create a project folder username_a07
. 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 project folder to username_a07.zip
file, validate it, and
submit it to the dropbox by the due date.
Write and test the following function:
def list_factors(num):
Add the function to a PyDev module named functions.py
.
Test it from .
list_factors
takes an integer greater than 0 as a
parameter (num
) and returns a list of the factors that
make up that number excepting the number itself. An integer's factors
are the whole numbers that the integer can be evenly divided by.
For example, the factors of 6 are 1, 2, and 3 because 6 can be evenly divided by all these numbers.
Determine even division with the modulus (%
)
operator. The modulus operator returns the remainder of an integer
division. Example: 6 % 3 → 0
.
The function does not ask for input and does no printing - that is done by your test program.
Provide the function docstring (documentation) following the CP104 style.
Sample execution:
list_factors(9)
[1, 3]
list_factors(97)
[1]
Test the function with three different sets of parameters.
Partial testing:
Write and test the following function:
def list_positives():
"""
-------------------------------------------------------
Gets a list of positive numbers from a user.
Negative numbers are ignored. Enter 0 to stop entries.
Use: numbers = list_positives()
-------------------------------------------------------
Returns:
numbers - A list of positive integers (list of int)
------------------------------------------------------
"""
Add the function to a PyDev module named functions.py
.
Test it from .
Sample execution:
list_positives()
Enter a positive number: 5 Enter a positive number: 7 Enter a positive number: 2 Enter a positive number: -7 Enter a positive number: -2 Enter a positive number: 0
and returns:
[5, 7, 2]
Test the function with three different sets of inputs.
Partial testing:
Write and test the following function:
def subtract_lists(minuend, subtrahend):
"""
-------------------------------------------------------
Updates the list minuend removing from it the values in subtrahend.
i.e. the values in the first list that appear in the second list
are not included in the updated list.
subtrahend is unchanged
Use: subtract_lists(minuend, subtrahend)
-------------------------------------------------------
Parameters:
minuend - a list of values (list)
subtrahend - a list of values to remove from minuend (list)
Returns:
None
------------------------------------------------------
"""
Add the function to a PyDev module named functions.py
.
Test it from .
Hint: you may use list_indexes
in the function to solve
the problem.
The function does not ask for input and does no printing - that is done by your test program.
Sample execution:
subtract_lists([1, 3, 5], [])
None
minuend after:
[1, 3, 5]
subtract_lists([1, 3, 5, 2, 4, 6], [3, 4])
None
minuend after:
[1, 5, 2, 6]
Test the function with three different sets of parameters.
Use list_positives
in your testing to get numbers from
the user.
Partial testing:
Partial testing of functions.py:
Partial testing of testing.txt: