Ask Your Question
1

if loop not working

asked 2016-08-03 17:32:40 +0100

nebuckandazzer gravatar image

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 ?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2016-08-03 18:34:23 +0100

updated 2016-08-03 20:05:36 +0100

You 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()
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2016-08-03 17:32:40 +0100

Seen: 339 times

Last updated: Aug 03 '16