CPSC120
Fundamentals of Computer Science

In-class Activity 8

  1. Factorial

    Create a Python function that returns the factorial of the specified integer. The function should use a loop to compute the product.

  2. Plot Sin

    Create a Python function that uses turtle graphics to plot the function f(x) = 100 sin(x / 10) in the domain  − w / 2 < x < w / 2, where w and h are the width and height of the canvas. The functions window_height and window_width in the turtle module can be used to get the dimensions of the window.

  3. Archimedes Approximation of pi

    Create a Python function that returns an approximation of pi using Archimedes’s algorithm given the number of sides of the polygon to approximate a circle with. The Archimedes’s algorithm computes the circumference of a regular polygon that approximates a circle and computes pi using the equation:

    circumference = 2 · pi · radius