Python If Statements


Here we will write a Sage subroutine containing an if/else statement. The subroutine will determine if a number passed to it is odd.

Sage Cell


def isOdd(n):
    if (n % 2 != 0):
        return true
        return false


If Comparators

When making a comparison there are a total of 6 comparators you may use. Here is the math notation and the Sage equivalent:

  • $>$ is >
  • $<$ is <
  • $\geq$ is >=
  • $\leq$ is <=
  • $=$ is ==
  • $\neq$ is !=

Note that equality is determined with a double equals sign, ==. If statements can also be controlled with boolean variables.


Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.




Date: 12 Mar 2019 17:37

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License