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

lenore borisova orangegirl at gmail.com
Mon Jul 4 10:56:03 UTC 2011


Hello, everybody. I am just starting this course now. Below are Lesson 2 and
Lesson 1 (in reverse chronological order).

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

LESSON 1

_______________________________________________


1. Python version that I am using is is Python 2.6.1 on Mac osX 10.6.8

2. Why are there two commas in
    print "Hello,", name
    ? What do you think the difference is between them?

The first comma prints the visible comma after the word "Hello" to the
screen. The second comma concatenates the "Hello" statement with the name
variable. I also noticed that it included a space.

3. Anyone know why the language was named Python?

After Monty Python's Flying Circus


More information about the Courses mailing list