Python: if Statements and Comparison Operators

Go to Chapter 9 in A Smarter Way.

An if statement in Python requires some careful punctuation and indentation:

    if this_cat == my_cat:
        # This cat is mine.
        print("%s is my cat!" % cat.title())

Note the comparison operator, ==, as opposed to the assignment operator, =.

Exercises

See http://www.asmarterwaytolearn.com/python/9.html

Go to Chapter 10 in A Smarter Way.

Note the list of operators available to you:

== # is equal
!= # not equal
> # greater than
< # less than
>= # greater or equal
<= # less or equal

Exercises

See http://www.asmarterwaytolearn.com/python/10.html

See http://introtopython.org/if_statements.html

  1. Return to examples.py.
  2. Do a test on the author’s name. If the name variable holds the proper name, print “Authorized Edition”.
  3. If the name variable doesn’t hold the proper name, print “No an Authorized Edition!”