CS8 Programming Assignment 2

CS8 Programming Assignment 2

In this Programming Assignment you will write two functions which take an integer argument m and compute an approximate value of π and returns it. The accuracy of the computed π for each function will depend on the value of the integer n which is the number of terms in the formula for π. If we take infinitely many terms, we can compute π exactly.
  1. The first function will be based on Leibniz formula:

    Since taking infinitely many terms is outside our ability, we can take finitely many terms, which is determined by the integer argument m. The function will be named as LeibnizPi(m) and will compute π as accurately as needed by selecting a larger value of m

    For example, if we take m=4, we will have the following approximation for π

    which is a bad approximation. If we need better approximations, we will need to take larger values of m. You are required to write the Python function LeibnizPi(m) that computes and returns π by taking m as the parameter.

  2. The second function will be named as BaselPi(m) and will be based on the Basel formula

    By taking m terms we compute an approximate value of π using the BaselPi(m) function as follows:

    You are required to write the Python function BaselPi(m) that computes and returns π by taking m as the parameter.

Place both of your functions LeibnizPi(m) and BaselPi(m) inside the Python file pa2.py and submit your file using the Dropbox link. Your functions will be tested using random values of m. Do not use any modules, including math in your programs.

Important: Add your full name and email address as a comment in the first line of your file, such as:
# Alice Smartpants (smartpants@umail.ucsb.edu)


cs8 web page