First time here? Check out the FAQ!

Ask Your Question
1

if loop not working

asked 8 years ago

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 ?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 8 years ago

updated 8 years ago

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()
Preview: (hide)
link

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: 8 years ago

Seen: 352 times

Last updated: Aug 03 '16