CPSC120A
Fundamentals of Computer Science I

Lab 10

Recursion

Use the command line to create a new directory called lab10 in your labs directory. Make sure all of the .py files that you create for this activity are in that directory.

Divisors

Create a Python function called print_divisors in a file called divisors.py. The function should use recursion to print all of the positive integers that are divisors of a specified positive integer. For example if the input is 12, the program would print:

12
6
4
3
2
1

Draw Polygon

Create a Python function called draw_polygon in a file called polygon.py. The function should use Pygame to draw a regular polygon. The function should have four parameters, the x and y coordinates of the center of the polygon, the distance from the center to a vertex of the polygon, and the number of sides of the polygon. The function should use recursion to draw all of the edges of the polygon. Recall from a previous activity that points on a circle can be computed using the following equations:

px = r ⋅ cosθ + cx
py = r ⋅ sinθ + cy

where (px, py) is a point on the circle with radius r and center (cx, cy). Because the polygon is regular, the difference in angle between all neighboring vertices is equivalent. Also, because the number of vertices is equivalent to the number of edges, the angle between neighboring vertices is 360 / n degrees, where n is the number of edges the polygon has.

Submission

Please show your source code and run your test cases for the instructor or lab assistant. Only a program that has perfect style, thorough test cases, and flawless functionality will be accepted as complete.