This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Learn Python the Hard Way

My recent threads

You haven't posted any discussions yet.

Recently updated threads

Exercise 7

Go back to: General discussion

Here's my source code and output without extra credit:
--- Source Code ---

print "Mary had a little lamb." 
print "Its fleece was white as %s." % 'snow' 
print "And everywhere that Mary went." 
print "." * 10 # that will print '..........'
 
end1 = "C" 
end2 = "h" 
end3 = "e" 
end4 = "e" 
end5 = "s" 
end6 = "e" 
end7 = "B" 
end8 = "u" 
end9 = "r" 
end10 = "g" 
end11 = "e" 
end12 = "r"
 
# if you remove the comma at the end it will print the statements on different lines
print end1 + end2 + end3 + end4 + end5 + end6, 
print end7 + end8 + end9 + end10 + end11 + end12

--- Output ---

Its fleece was white as snow.
And everywhere that Mary went.
..........
Cheese Burger

EXTRA CREDIT
The first part was to add comments which I didn't think was neccasary
and the rest was about debugging and I didn't make any mistakes the first time so I didn't do any of it.
but out of interest can some of you guys comment the mistakes

Fairly easy exercise

Rodrigo Zerbini's picture
Rodrigo Zerbini
Wed, 2011-01-26 22:58

Here's my source code with commentaries:

# just print the string
print "Mary had a little lamb"

# print the string with the format character %s
print "Its fleece was white as %s." % 'snow'

# just print the string
print "And everywhere that Mary went."

# the "." followed by * 10 will print 10 dots
print "." * 10 # what'd that do?

end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"

# watch that comma at the end. try removing it to see what happens
# the comma has the function of printing all the ends on the same line (without the comma the word Burger is printed on another line)
print end1 + end2 + end3 + end4 + end5 + end6,
print end7 + end8 + end9 + end10 + end11 + end12

Arbi Derhartunian's picture
Arbi Derhartunian
Thu, 2011-01-27 01:00

wow are we in week 7 yet you must be super ahead

jennifer karmon's picture
jennifer karmon
Fri, 2011-02-04 03:20

Nope, not super ahead. We're supposed to do four exercises each week.

Dorene DeMars's picture
Dorene DeMars
Wed, 2011-02-09 08:25

Here's my program...the first time I ran it I had forgotten end5, end9 and end10 in the last two lines. My output looked like Cheee Buer. I am not sure why I missed those...

My question...we used 'end1''end2' etc. to define the letters for the Cheese Burger output. Is there something special about 'end ' ? Or was that just something random the author chose?

print "Mary had a little lamb."
print "Its fleece was white as %s." % 'snow'
print "And everywhere that Mary went."
print "." * 10 # what'd that do?

end1 = "C"
end2 = "h"
end3 = "e"
end4 = "e"
end5 = "s"
end6 = "e"
end7 = "B"
end8 = "u"
end9 = "r"
end10 = "g"
end11 = "e"
end12 = "r"

# watch that comma at the end. try removing it to see what happens
print end1 + end2 + end3 + end4 + end5 + end6,
print end7 + end8 + end9 + end10 + end11 + end12

Guntis L's picture
Guntis L
Wed, 2011-02-09 16:34

If you replace 'end ' with whatever you want, you get the same result, so there's nothing special.