[Tutor] while statement

antonmuhin at rambler.ru antonmuhin at rambler.ru" <antonmuhin@rambler.ru
Thu May 1 06:47:01 2003


Hello Mic,

Thursday, May 1, 2003, 10:37:50 AM, you wrote:

MF> Hi,

MF> What I want to do is quite simple but I have gotten
MF> myself into a bind and any help is much appreciated.
MF> In a nutshell I need to iterate through the follow
MF> equation:

MF> S(n) = [S(S-1)/N](1-n/N)**S-2

MF> where S and N are fixed values but where n increases
MF> by 1 after each iteration. So if S=31 and N=834 then
MF> after the first iteration:

MF> S(1) = [31(31-1)/834](1-1/834)**31-2
MF>      = 1.077

MF> Second iteration:

MF> S(2) = [31(31-1)/834](1-2/834)**31-2
MF>      = 1.04

MF> and this is repeated until n = N.

MF> I know that the while statement needs to be used but I
MF> am unsure of the exact syntax. I am having problems
MF> incrementing n by 1 in each iteration.

MF> Thanks again for any help,
MF> Mic

MF> __________________________________
MF> Do you Yahoo!?
MF> The New Yahoo! Search - Faster. Easier. Bingo.
MF> http://search.yahoo.com


You might use something like this:

for n in range(1, N): # or range(1, N + 1), if you need to compute for N too
    print float(S)*...

BTW (S*(S-1)/N) might be precomputed.



-- 
Best regards,
 anton                            mailto:antonmuhin@rambler.ru