[Tutor] need help tracing a syntax error
Kermit Rose
kermit at polaris.net
Sat Mar 11 16:42:31 CET 2006
def vmod(a , b ):
.r1 = b
.r2 = a
. m1 = 0
.m2 = 1
.q = Int(r1 / r2)
.r3 = r1 - q * r2
.m3 = m1 - q * m2
.while r3 != 0:
...r1 = r2
...m1 = m2
...r2 = r3
...m2 = m3
...q = Int(r1 / r2)
...r3 = r1 - r2 * q
...m3 = m1 - m2 * q
.If r2 == 1:
...If m2 < 0:
.....return( m2 + b)
...Else:
.....return( m2 )
.Else:
...return( -r2 )
When I attempt to run this function from the shell run menu,
I get the message
syntax error
and it highlights r2
in the line
.If r2 == 1:
However if I
use the eval function in the shell, I get
>>> eval("factor30")
<module 'factor30' from 'c:\math\factoring\factor30.pyc'>
>>>
no error message.
and when I use help to look at the associated module,
this function is not listed. It must be because of the syntax error.
>>> help(factor30)
Help on module factor30:
NAME
factor30
FILE
c:\math\factoring\factor30.py
FUNCTIONS
factor(z)
factor0(z)
gcd(a, b)
ifprime(z)
ksqrt(j)
test(tv)
transfac(v)
Give me some hint for why this is happening.
The periods at the beginning of each line represents beginning spaces.
More information about the Tutor
mailing list