CSC207 Fayetteville State University Python Methods Questions

Fayetteville State UniversityDepartment of Mathematics
and Computer Science
CSC207 Symbolic Programming
Assignment 4
Due Date: April 03
Spring 2022
Albert Chan
Page 1 of 3
Important information about plagiarism:
While you are encouraged to discuss lecture topics with your peers, assignments must be your own work
and plagiarism of any kind will not be tolerated. Submitted assignments will be automatically cross-checked
with all other submissions in the class. Anyone who plagiarizes (i.e., copies code or allows their code to be
copied by others) will receive a zero (0) on the assignment and be referred to the department chair for more
severe disciplinary action.
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 comprehension.
Given a positive integer value n, a proper factor of n is defined to be an integer value i between 1 to n
(exclusively) such that n is divisible by i; that is, the remainder of dividing n by i is zero (0). Note that although
n is divisible by both 1 and n, they are not proper factors of n.
The function factors has the following signature:
def factors(n):
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 (843)
• factors (3281)
• factors (6912)
• factors (6693)
• factors (2778)
• factors (4027)
➔ [3, 281]
➔ [17, 193]
➔ [2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 27, 32, 36, 48, 54, 64,
72, 96, 108, 128, 144, 192, 216, 256, 288, 384, 432, 576,
768, 864, 1152, 1728, 2304, 3456]
➔ [3, 23, 69, 97, 291, 2231]
➔ [2, 3, 6, 463, 926, 1389]
➔ []
Note that the output for the last example is an empty list since 4,027 is a prime number and it has no proper
factor.
Download the three files “csc207a4.py”, “csc207a4_tester.py”, “csc207a4_testdata.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 “csc207a4.py” 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
Department of Mathematics
and Computer Science
CSC207 Symbolic Programming
Assignment 4
Due Date: April 03
Spring 2022
Albert Chan
Page 2 of 3
def factors(n):
return [n]
The tester program will use the test data to test your implementation. It will run a total of 100 test cases. If
your function is implemented correctly, running the tester should produce the following output:
Passed: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18,
19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36,
37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72,
73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 100] – total 100.
Failed: [] – total 0.
0 of 100 test cases passed. Score = 20.00 of 20.00
If you would like, you can look up the test data from the file csc207a4_testdata.py. This file defines a
single list named tests, which consists of 100 tuples. Each tuple is a test, and it has 3 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:
# csc207_testdata.py
“”” Test data for Assignment 4. “””
TESTS = [(1, 2464, [2, 4, 7, …, 352, 616, 1232]),
(2, 3288, [2, 3, 4, …, 822, 1096, 1644]),
(3, 9676, [2, 4, 41, 59, 82, 118, 164, 236, 2419, 4838]),
(4, 1179, [3, 9, 131, 393]),
(5, 4639, []),

Notes:
1. Your program will be tested with similar but different data. The testing results will earn you up to 20
points – this is your execution score.
2. There cannot be any import statement in your program – otherwise, 20% of your execution score
will be deducted.
3. There can be only one single function (the factors function) defined in the “csc207a4.py” file. No
other helper function(s) is/are allowed. Otherwise, 20% of your execution score will be deducted.
Fayetteville State University
Department of Mathematics
and Computer Science
CSC207 Symbolic Programming
Assignment 4
Due Date: April 03
Spring 2022
Albert Chan
Page 3 of 3
4. You must have meaningful documentation (in form of comments) to explain what is going on in your
implementation. Otherwise, 20% of your execution score will be deducted. Documentation should be
in the form of Python comments.
5. Your code should NOT produce any output on the screen. Otherwise, 20% of your execution score
will be deducted.
6. Your function CANNOT use recursion and MUST use list comprehension, otherwise your final score
will be reduced by 90%.
7. In general, you should not use variables. If you think you need to use variables, the variables should
be assigned a value only once (this is to mimic the immutability of functional programming).
8. The tester contains a function “run_testcase”. This function takes a testcase number and runs that
single testcase. It will produce a more verbose output to help you debug your program.
>>> run_testcase(50)
Test 50 failed – expecting a list of length 2, got one of length 1 instead.
Please note that this function is not executed by default when you load the tester. So, you may need
to somehow activate Python in interactive mode to use this function. If you are using Python IDLE,
you are automatically put in the interactive mode after loading (and executing) the module. However,
this is not the default if you are invoking and running Python from the command line. To allow you to
use the function if you load the tester from the command line, you must use the interactive flag when
invoking Python:
> python -i csc207a4Tester.py
After you are done, you can use the exit() function to abort the Python session.
Submit only the file “csc207a4.py” to Canvas. Deadline is Sunday April 03.

Save Time On Research and Writing
Hire a Pro to Write You a 100% Plagiarism-Free Paper.
Get My Paper
Still stressed from student homework?
Get quality assistance from academic writers!

Order your essay today and save 25% with the discount code LAVENDER