Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to do an "if" block in Sage?

I am trying to do an if block in sage. For example, I have code: for n in range(7): if gcd(n,3)==3: n=n/3; n=n+1; print(n)

This "should" only add one when n is divisible by 3, but seems to do this all the time. Any ideas?

click to hide/show revision 2
No.2 Revision

How to do an "if" block in Sage?

I am trying to do an if block in sage. For example, I have code: code:

for n in range(7):
    if gcd(n,3)==3:
        n=n/3;
        n=n+1;
    print(n)

print(n)

This "should" only add one when n is divisible by 3, but seems to do this all the time. Any ideas?