On Fri, Oct 24, 2008 at 6:51 AM, W W <[EMAIL PROTECTED]> wrote:
> for i in range(1, n+1):
> x = x + (m * (i % 2)) * (4.0/(i*2))
This will omit every other term (when i%2 ==0) and it divides by the
even numbers, not odd ones.
Kent
___
Tutor maillist
On Thu, Oct 23, 2008 at 10:29 PM, Monte Milanuk <[EMAIL PROTECTED]> wrote:
> Hello again, and thanks to all of you who extended your help!
> Maybe I'm not clever enough, but I didn't see how either example
> could be used for doing the addition/subtraction determination. Or rather,
> I found a di
Hello again, and thanks to all of you who extended your help!
Wayne,
Thanks for your examples. They did end up helping in with finding a pattern to
do the odd numbers with. Maybe I'm not clever enough, but I didn't see how
either example could be used for doing the addition/subtraction determ
On Thu, Oct 23, 2008 at 10:20 AM, bob gailer <[EMAIL PROTECTED]> wrote:
> import operator
> ops = (operator.add, operator.sub)
> x = 0
> m = 0
> for in in range...
> x = ops[m](x, 4.0/i)
> m = 1-m
itertools.cycle(ops) is handy here. Hmm, there is a cute one-line
solution (excluding import an
Why not throw in itertools.cycle while you're at it? ;-)
pi = sum(4. / (1+x) * itertools.cycle((1,-1)).next() for x in range(0,
4 * n, 2))
I'd also be so tempted just to call the file 'approximate' (read it
with extension...)
Let's also not forget about integer division...
2008/10/23 bob gailer
Monte Milanuk wrote:
Hello all,
New guy here, so go easy on me ;)
We save the whips and chains for the more hardened questers. Newcomers
get the feathers.
I'm starting to work my way through Python Programming by Zelle, and
have hit a bit of a wall on one of the prog
On Thu, Oct 23, 2008 at 12:09 AM, Monte Milanuk <[EMAIL PROTECTED]> wrote:
> def main():
> print "This program will approximate the value of pi"
> print "to a degree determined by the user. "
> print
>
> # get the value of n from the user
> n = input("How many terms do you wan
On Wed, Oct 22, 2008 at 11:09 PM, Monte Milanuk <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> New guy here, so go easy on me ;)
>
Welcome to python and the tutor list!
> I'm starting to work my way through Python Programming by Zelle, and have
> hit a bit of a wall on one of the programming exerc
Hello all,
New guy here, so go easy on me ;)
I'm starting to work my way through Python Programming by Zelle, and have hit a
bit of a wall on one of the programming exercises in Chapter 3 (#15 if anyone
has the book handy).
What the question ask is: Write a program that approimates the valu