Re: can't solve an exercise-help me with it



"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.
.



Relevant Pages

  • Re: cant solve an exercise-help me with it
    ... > I'm studying python newly and have an exercise that is difficult for me as a ... > "Write a program that approximates the value of pi by summing the terms of ... > number of terms to sum and then output the sum of the first n terms of this ... sum += num / den ...
    (comp.lang.python)
  • cant solve an exercise-help me with it
    ... I'm studying python newly and have an exercise that is difficult for me as a ... "Write a program that approximates the value of pi by summing the terms of ... number of terms to sum and then output the sum of the first n terms of this ... Prev by Date: ...
    (comp.lang.python)
  • Re: cant solve an exercise-help me with it
    ... >I'm studying python newly and have an exercise that is difficult for me as a ... >"Write a program that approximates the value of pi by summing the terms of ... >number of terms to sum and then output the sum of the first n terms of this ... Hint2: ...
    (comp.lang.python)
  • Re: Comments needed for attempted proof of a simple integral
    ... > X" problems aren't so difficult because standard math education has been ... > about solving problems of that nature and I can usually verify answers ... > exercise for me to verify, and there are a lot of those in this book. ... >> My thinking is to translate the integral into a sum, ...
    (sci.math)
  • Steve Summit C notes , exercise
    ... this is the programme i created, for exercise 2, assignment 3 at ... the average of the squares of the numbers from 1 to 10. ... the sum of all ...
    (comp.lang.c)