[Courses] [python] Lesson 2: Loops, if, and beer

lenore borisova orangegirl at gmail.com
Mon Jul 4 10:47:39 UTC 2011


These are my answers for Lesson 2.

--Lenore


Lesson 2: Problem 1:

for beer in range(99,0,-1)      :

        str1 = "bottles of beer on the wall,"
        str2 = "bottle of beer on the wall,"
        str3 = "No more bottles of beer on the wall,"
        str3b = "no more bottles of beer on the wall."

        str4 = "bottles of beer."
        str5 = "bottle of beer."
        str6 = "no more bottles of beer."

        str7 = "Take one down and pass it around,"
        str8 = "Go to the store and buy some more,"
        str9 = "bottles of beer on the wall."
        str9b = "bottle of beer on the wall."

        total = 99

        if beer >= 3    :
                print beer,str1,beer,str4
                print str7,beer-1,str9,"\n"
        elif beer == 2  :
                print beer,str1,beer,str4
                print str7,beer-1,str9b,"\n"
        elif beer == 1  :
                print beer,str2,beer,str5
                print str7,str3b,"\n"
        else    :
                "there is a loop error"

print str3,str6
print str8,total,str9,"\n"

Lesson 2: Problem 2:

It gives an empty set because if you subtract -1 from 0, you will always get
0.

Lesson 2: Problem 3:

Just right

Lesson 2: Problem 4:

for i in range(1,6)     :
        if i == 1       :
                print "one"
        elif i == 2     :
                print "two"
        elif i == 3     :
                print "three"
        elif i == 4     :
                print "four"
        elif i == 5     :
                print "five"
        else    :
                print "error in loop"


More information about the Courses mailing list