logo
Published on Models of Motion (http://www2.evergreen.edu/modelsofmotion)

Read Code Week 3

Read the following 4 Python programs.  For each, predict the output on paper, then run the code.  If you were not correct, find where you made your mistake.  Change the programs and predict the output for the new programs.

a=7
b=3
c=1
c=a-b-c
if a>2*b+1:
    print "yes"
while c<a:
    while b>0:
        print a+b+c
        b=b-1
    print"more",a
    a=a-1
    b=a-2
if a>1: print "last"
print "another",b

a=9
b=5
c=a-b
if c<b:
    print "yes"
while c<a:
    print"do it",c
    while b>0:
        print a+b+c
        b=b-2
    print"more",a
    a=a-2
    b=a-2
if a>1: print "last"
print "another",b

a=9
b=5
c=a-b
while a>c:
    if a==7:
        print"do it",c
        a=a+1
    while b>0:
        print a+b-c
        b=b-2
    print"more",c
    b=a-c
    c=c+2
if a>1: print "last"
print "another",b

a=9
b=5
c=a-b
while a>c:
    if c==7:
        print"do it",c
        while b>0:
            print a+b-c
            b=b-2
            a=a+1
    while b>0:
        print"more",b
        b=b-2
    b=a-c
    c=c+3
if a>1: print "last"
print "another",b


Source URL:
http://www2.evergreen.edu/modelsofmotion/modelsofmotion/read-code-week-3