Question: In this assignment, you are going recode the factors function in Assignment 3 using Python to find the proper factors of a number using list
In this assignment, you are going recode the factors function in Assignment using Python to find the
proper factors of a number using list comprehension.
Given a positive integer value n a proper factor of n is defined to be an integer value i between to n
exclusively such that n is divisible by i; that is the remainder of dividing n by i is zero Note that although
n is divisible by both and n they are not proper factors of n
The function factors has the following signature:
def factorsn:
This function should return a list of unique integer values. The elements in the list are all proper factors of the
parameter, and they must be in ascending order.
Here are some examples:
factors
factors
factors
factors
factors
factors
Note that the output for the last example is an empty list since is a prime number and it has no proper
factor.
Download the three files cscapycscatester.pycscatestdata.py from Canvas
and save them in the same folder. The last two files are the tester program and the testing data file,
respectively. Do not modify these two files. The first file is the file you will work on Note that you cannot
rename this file and you cannot change the name of the function otherwise the tester will not be able to pick
up your implementation However, you can change the name of the parameter if you like.
The file cscapy contains a dummy implementation of the function that always returns an incorrect
value. The contents of this file is listed here for your reference:
Fayetteville State University CSC Symbolic Programming Spring
Department of Mathematics Assignment Albert Chan
and Computer Science Due Date: April Page of
def factorsn:
return n
The tester program will use the test data to test your implementation. It will run a total of test cases. If
your function is implemented correctly, running the tester should produce the following output:
Passed:
total
Failed: total
of test cases passed. Score of
If you would like, you can look up the test data from the file cscatestdata.py This file defines a
single list named tests, which consists of tuples. Each tuple is a test, and it has values inside:
The first is an integer representing the test id
The second is the input parameter.
The last is the expected result of calling factors using the input parameters.
The following is the first few lines in the test data file:
# csctestdata.py
Test data for Assignment
TESTS
Notes:
Your program will be tested with similar but different data. The testing results will earn you up to
points this is your execution score.
There cannot be any import statement in your program otherwise, of your execution score
will be deducted.
There can be only one single function the factors function defined in the cscapy file. No
other helper functions isare allowed. Please note that you also can neither define a nested function
using this code:
def factors n:
return n
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
