Python problem

Steven D'Aprano steve+comp.lang.python at pearwood.info
Tue Feb 19 23:22:51 EST 2013


On Tue, 19 Feb 2013 19:01:53 -0800, ach360 wrote:

> I'm so lost. Given the formula pi=4-4/3+4/5-4/7+4/9-4/11+...... How do I
> print a table showing approximate value of pi by computing one term4-4/3
> then two terms4-4/3+4/5, and so on.Then how many terms of the series
> before I get 3.14, 3.141, 3.1415, 3.14159. Please helps computer teacher
> literally says figure it out and doesn't help and expects a perfect
> program.this is in python 3 please give an answer I can understand and
> an example. Thanks :) :)

First, you need to know what the formula for pi actually is. You can find 
that by googling, or look it up in a maths book. You should expect 
something like

pi = sum from i=0 to infinity of 4 divided by (something)


Then you want a program to print a table that looks something like this:

i   value
0   xxxxx
1   xxxxx
2   xxxxx


etc., where the "xxxxx" will get filled in later, and the table stops at 
a certain maximum value of i. Here is a hint:


for i in range(100):
    x = "calculate something"
    print("%d   %s" % (i, x)


Does that get you started? Try writing some code and see how far you get.


Good luck!




> I need this right now.
> Thanks for your time.
> 
> I need this ASAP

Then you better get started straight away then. Turn off Facebook and 
Twitter and do some real work.


-- 
Steven




More information about the Python-list mailing list