CSC111 Exercises with IF statements 2014

From dftwiki3
Revision as of 09:10, 12 February 2014 by Thiebaut (talk | contribs) (Created page with "__TOC__ <br /> ==Source== <source lang="python"> # if_tests.py # D. Thiebaut # A collection of if/else statements. # Figure out what gets printed! def f1(): a = 3 b =...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents


Source

# if_tests.py
# D. Thiebaut
# A collection of if/else statements.
# Figure out what gets printed!

def f1():
    a = 3
    b = 5
    c = 10
    if a < b:
        print "statement 1"
    else:
        if a < c:
            print "statement 2"
        else:
            if b < c:
                print "statement 3"
    print "f1 done!"

def f2():
    a = 30
    b = 5
    c = 10
    if a < b:
        print "statement 1"
    else:
        if a < c:
            print "statement 2"
        else:
            if b < c:
                print "statement 3"
    print "f2 done!"

def f3():
    a = 30
    b = 50
    c = 10
    if a < b:
        print "statement 1"
    else:
        if a < c:
            print "statement 2"
        else:
            if b < c:
                print "statement 3"
    print "f3 done!"

def f4():
    a = 30
    b = 5
    c = 10
    if a < b < c:
        print "statement 1"
    else:
        if a < c < b:
            print "statement 2"
        else:
            print "statement 3"
        print "statement 4"
    print "f4 done!"

def f5():
    a = 30
    b = 50
    c = 10
    if a < b < c:
        print "statement 1"
    else:
        if a < c < b:
            print "statement 2"
        else:
            print "statement 3"
        print "statement 4"
    print "f5 done!"

def f6():
    a = 3
    b = 5
    c = 1
    if a < b < c:
        print "statement 1"
    else:
        if a < c < b:
            print "statement 2"
        else:
            print "statement 3"
        print "statement 4"
    print "f6 done!"