[Tutor] Beginner Exercise: Why Didn't I Break It?

Homme, James james.homme at highmark.com
Tue Dec 20 18:31:49 CET 2011


Hi,
Please don't give me the answer. Please tell me where to read to find out.

So far, the data types this little book has talked about are strings and numbers.

The book is here. http://learnpythonthehardway.org/book/

I cut out the parts of the program I definitely understand to focus on this part.

This exercise is a practice exercise that talks about functions. The instructions were to try to break the file and make it not run, so I decided to try to call the below function with one argument instead of three. I'm trying to explain to myself why it didn't break. I have comments in here for what I think is going on.

# This function takes one argument.
# It returns three items.

def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates

start_point = 10000

# It returns three things in parentheses, which, I guess is one group of things. I thought it would complain.
stuff = secret_formula(start_point)
print stuff
# This is three items, according to me. It makes three separate variables, that we print out below.
beans, jars, crates = secret_formula(start_point)

print "We have %d beans, %d jars, and %d crates." % (beans, jars, crates)

Thanks.

Jim
Jim Homme,
Usability Services,
Phone: 412-544-1810.


________________________________

This e-mail and any attachments to it are confidential and are intended solely for use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please notify the sender immediately and then delete it. If you are not the intended recipient, you must not keep, use, disclose, copy or distribute this e-mail without the author's prior permission. The views expressed in this e-mail message do not necessarily represent the views of Highmark Inc., its subsidiaries, or affiliates.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111220/415e1b4c/attachment.html>


More information about the Tutor mailing list