Instructions

The German mathematician Gottfried Leibniz developed the following method to approximate the value of π:

π/4 = 1 - 1/3 + 1/5 - 1/7 + . . .

Write a program that allows the user to specify the number of iterations used in this approximation and that displays the resulting value.

An example of the program input and output is shown below:

Enter the number of iterations: 5

The approximation of pi is 3.3396825396825403

Flowchart

To enlarge flowchart turn side navigation off, Click on Side Navigation button on in the top navigation bar to change to Side Navigation button off


Flowchart
Flowchart

Starter Code

"""
Program: leibniz.py
Project 3.6
This program approximates the value of pi using an algorithm
designed by the German mathematician Gottfried Leibniz. The
algorithm is as follows:
pi = 4 - 4 / 3 + 4 / 5 - 4 / 7 + . . .
This program allows the user to specify the number of iterations
to use in the approximation.
"""
# Request the inputs

# Initialize loop variables

# Loop through iterations

    # Calculate π/4 for this iteration 

# Output results
Tags: