Ask Your Question

A confusing syntax error when using elif

asked 2015-04-14 18:04:19 +0200

Haron gravatar image

Dear All

This is my confusing problem:

sage: m=31
sage: if m%3==0:
....:     print m/3
....:     elif m%3==1:
....:         print (m-1)/3
File "<ipython-input-2-ec9f38b42615>", line 3
  elif m%Integer(3)==Integer(1):
SyntaxError: invalid syntax


I do not copy-paste the code. I have ubuntu14.04 and my sage version is 6.5.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-04-14 18:12:28 +0200

Nathann gravatar image

The 'elif' should not be inside of the 'if'

edit flag offensive delete link more


Thank you. I understand.

Haron gravatar imageHaron ( 2015-04-14 18:27:19 +0200 )edit

@Haron - if this completely answered your question, please don't forget to "accept" by clicking the check mark, so that people coming to this site with the same question know they will find an answer. Thanks!

kcrisman gravatar imagekcrisman ( 2015-04-14 20:27:14 +0200 )edit

@kcrisman Thank you Kcrisman. Sorry for this delaying.

Haron gravatar imageHaron ( 2015-04-15 20:07:28 +0200 )edit

No problem, just a reminder for future visitors - glad Nathann could help!

kcrisman gravatar imagekcrisman ( 2015-04-15 20:17:28 +0200 )edit

That is the person who gave you this answer :)

kcrisman gravatar imagekcrisman ( 2015-04-15 22:49:44 +0200 )edit

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


Asked: 2015-04-14 18:04:19 +0200

Seen: 387 times

Last updated: Apr 14 '15