Please Help Explain

Andrei project5 at redrival.net
Thu Nov 6 16:33:25 CET 2003


Jakle wrote on Thu, 06 Nov 2003 04:01:21 GMT:

> I was at a job interview one day and the owner of the start up company asked
> me if I'd rather make $1000 dollars a day, or start off with a penny a day
> and double the amount every day for 30 days. I was too lazy to sit down with
> paper and pen to figure out how much the second choice came out to. But now

You don't really need a special function for that, just the ** operator :).

<snip> 
> I completely stumbled across it and it works. I just don't understand how
> the value of n is assigned to the second n in "n=n*2" once it loops back

This simply is run like this:

 - take the value of n
 - multiply it with 2
 - store the result as n again

It's not trying to both read and assign n at the same time. It's a bit
weird if you look at it from a mathematical standpoint (solve "x=x+2"), but
you shouldn't look at it that way.

-- 
Yours,

Andrei

=====
Mail address in header catches spam. Real contact info (decode with rot13):
cebwrpg5 at bcrenznvy.pbz. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V
ernq gur yvfg, fb gurer'f ab arrq gb PP.






More information about the Python-list mailing list