Re: can't solve an exercise-help me with it
- From: Tim Roberts <timr@xxxxxxxxx>
- Date: Thu, 12 Jan 2006 07:59:56 GMT
"hossam" <nono@xxxxxxxxxxx> wrote:
>I'm studying python newly and have an exercise that is difficult for me as a
>beginner.Here it is :
>"Write a program that approximates the value of pi by summing the terms of
>this series:
>4/1-4/3+4/5-4/7+4/9-4/11+.... The program should prompt the user for n, the
>number of terms to sum and then output the sum of the first n terms of this
>series."
>
>any help would be appreciated.
Is this homework? You should show us what you already have, and we can
show you where may be going wrong. This isn't a free homework service.
This is not a hard problem, although that's a terrible series for computing
pi. At 100,000 terms, it still only has 5 digits.
n = input( "How many terms? " )
sum = 0
sign = 4.0
for i in range(n):
sum += sign / (i+i+1)
sign = -sign
print sum
--
- Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- References:
- can't solve an exercise-help me with it
- From: hossam
- can't solve an exercise-help me with it
- Prev by Date: Re: Python Scripts to logon to websites
- Next by Date: Re: MVC in wxPython HELP!
- Previous by thread: Re: can't solve an exercise-help me with it
- Index(es):
Relevant Pages
|