ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 03 Aug 2016 18:34:23 +0200if loop not workinghttps://ask.sagemath.org/question/34320/if-loop-not-working/ I have to use an if loop in my program. I am checking the irreducibility of a collection of polynomials. If f(x) is a reducible polynomial, then I want to find its factor. This is my code
v=f.is_irreducible()
if (v==0) f.factor()
But I am getting a syntax error. Can someone help me ?
Wed, 03 Aug 2016 17:32:40 +0200https://ask.sagemath.org/question/34320/if-loop-not-working/Answer by John Palmieri for <p>I have to use an if loop in my program. I am checking the irreducibility of a collection of polynomials. If f(x) is a reducible polynomial, then I want to find its factor. This is my code</p>
<pre><code>v=f.is_irreducible()
if (v==0) f.factor()
</code></pre>
<p>But I am getting a syntax error. Can someone help me ?</p>
https://ask.sagemath.org/question/34320/if-loop-not-working/?answer=34323#post-id-34323You need a colon:
if (v==0): f.factor()
I would actually write this as:
if not f.is_irreducible():
f.factor()
Your assignment of `v=f.is_irreducible()` doesn't seem to be necessary unless you want to use `v` several times later. If so, you could do
v = f.is_irreducible()
if not v: # better than checking v == 0
f.factor()Wed, 03 Aug 2016 18:34:23 +0200https://ask.sagemath.org/question/34320/if-loop-not-working/?answer=34323#post-id-34323