Difference between revisions of "CSC111 Exercises with IF statements 2014"

From dftwiki3
Jump to: navigation, search
(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 =...")
 
Line 1: Line 1:
 +
--[[User:Thiebaut|D. Thiebaut]] ([[User talk:Thiebaut|talk]]) 09:10, 12 February 2014 (EST)
 +
----
 +
 
__TOC__
 
__TOC__
 
<br />
 
<br />

Revision as of 10:10, 12 February 2014

--D. Thiebaut (talk) 09:10, 12 February 2014 (EST)


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!"