Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #39303 > unrolled thread

Python problem

Started byach360@gmail.com
First post2013-02-19 19:01 -0800
Last post2013-02-20 04:22 +0000
Articles 4 — 3 participants

Back to article view | Back to comp.lang.python


Contents

  Python problem ach360@gmail.com - 2013-02-19 19:01 -0800
    Re: Python problem Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-02-19 23:10 -0500
      Re: Python problem ach360@gmail.com - 2013-02-19 20:36 -0800
    Re: Python problem Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-02-20 04:22 +0000

#39303 — Python problem

Fromach360@gmail.com
Date2013-02-19 19:01 -0800
SubjectPython problem
Message-ID<d8fe7094-3f11-4d18-88cc-a75dbf1b832e@googlegroups.com>
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 :) :) 
I need this right now. 
Thanks for your time.

I need this ASAP

[toc] | [next] | [standalone]


#39309

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-02-19 23:10 -0500
Message-ID<mailman.2083.1361333412.2939.python-list@python.org>
In reply to#39303
On Tue, 19 Feb 2013 19:01:53 -0800 (PST), ach360@gmail.com declaimed the
following in gmane.comp.python.general:

> 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 :) :) 
> I need this right now. 
> Thanks for your time.
> 
> I need this ASAP

	It is homework... No one will give you an answer... Normally we'd
ask you to show use what you have tried, and we'd try to suggest where
you went wrong. I'll give you five hints...

	HINT: The first term of the equation is equivalent to 4/1
	HINT: The denominators are odd integers.
	HINT: Each iteration is adding 4/<nextodd> to the preceding sum
	HINT: Subtraction is the addition of a negative value
	HINT: Each "even" term is a subtraction



-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
        wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#39313

Fromach360@gmail.com
Date2013-02-19 20:36 -0800
Message-ID<4379615c-75fe-4b36-8a5a-0e4f49c9351c@googlegroups.com>
In reply to#39309
Loop_variable= 1
Pi=1.0
term=0
T=1.0
While (loop_variable> 0):
     Loop_variable=Loop_variable+1
     T=T+2.0
     
If (loop_variable%2 ==0):
             Term=0;
Else:
      term=1;


If term  ==0:
         Pi=Pi- float(1/T);
Else:
       Pi=Pi+ float(1/T);


     

[toc] | [prev] | [next] | [standalone]


#39312

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2013-02-20 04:22 +0000
Message-ID<51244f9b$0$11096$c3e8da3@news.astraweb.com>
In reply to#39303
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web