[Tutor] new and freezing problem
Michael Janssen
Janssen@rz.uni-frankfurt.de
Mon May 26 07:01:45 2003
On Sun, 25 May 2003, Jennifer Cianciolo wrote:
> Hi!
>
> I'm new to this list. I have no programming experience, but I'm
> trying to teach myself some with python.
>
> I've written a short program that keeps making my computer freeze.
> Actually it's not the whole computer, just python. This is the
> program:
>
> def freqChange(p, N, w11, w12, w22):
> q=1-p
> pnew=(N*(p**2*w11+q*p*w12))/(N*(p**2*w11+2*p*q*w12+q**2*w22))
> while 0<=pnew<=1.0:
> p=pnew
> q=1-pnew
> print pnew
adding a "print" statement is your friend:
def freqChange(p, N, w11, w12, w22):
q=1-p
pnew=(N*(p**2*w11+q*p*w12))/(N*(p**2*w11+2*p*q*w12+q**2*w22))
while 0<=pnew<=1.0:
print pnew # <-- here
p=pnew
q=1-pnew
print pnew
freqChange(1, 1, 1, 1, 1)
---> prints lost of "1" ----> pnew never gets change inside the "while"
loop.
Even putting pnew's formular inside the loop:
def freqChange(p, N, w11, w12, w22):
q=1-p
pnew = 0.5 # enter the loop at least one time
while 0<=pnew<=1.0:
pnew=(N*(p**2*w11+q*p*w12))/(N*(p**2*w11+2*p*q*w12+q**2*w22))
print pnew
p=pnew
q=1-pnew
print pnew
dosn't change this behaviour (but: my startup values 1, 1, 1, 1, 1
possibly arn't sensibly. It's a pity that you havn't provide some real
cases). But it's left to you to use better startup values or debug the
formular, so that it change pnew's value to something outside of [0.0-1.0]
(and break the while loop condition).
The print statement is all you need as debug-information.
Michael
>
>
> any ideas what might be wrong??
>
> thanks in advance
> Jen
>
> _______________________________________________
> Tutor maillist - Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>