need help translating a PHP for statement to python

Michael T. Babcock mike at triplepc.com
Sat Jan 10 12:58:02 EST 2004


>
>
>If someone could explain to me how one should
>translate the multiple increment, evaluations, etc. in the first line
>I would appreciate it deeply ...
>
>for ($y = 0, $x = $cx-$cy-1; $y <= $cy; ++$y,++$x) {
>    $prd = $q * $y_ar[$y] + $car;
>    $prd -= ($car = intval($prd / 1E7)) * 1E7;
>    if ($bar = (($x_ar[$x] -= $prd + $bar) < 0)) $x_ar[$x] += 1E7;
>    }
>
>  
>

In all likelihood, you could rewrite the algorithm (if you understand 
it) in Python in a more Pythonesque kind of way and make it easier to 
maintain in the future, but this should do it:

y = 0
x = cx - cy - 1
while y <= cy:
    prd = q * y_ar[y] + car
    # { and so on }
    x += 1
    y += 1

... that should do it for you, should it not?
-- 
Michael T. Babcock
http://www.fibrespeed.net/~mbabcock/code




More information about the Python-list mailing list