The function part of this program (everything after def
) is not working. I have no error messages, and I believe I've typed everything the way Zed did. What's wrong?
print "Let's practice everything."
print 'You\'d need to know \'bout escapes with \\ that do \n newlines and \t tell'
# newline and a space are put in, tab and a space are put in
# this doesn't print the poem, only stores it
poem = """
\tThe lovely world
with logic so firmly planted
cannot discern \n the needs of love
nor comprehend passion from intuition
and requires an explanation
\n\t\t where there is none
"""
print "--------------"
print poem
print "--------------"
five = 10 - 2 + 3 -6
print "This should be five: %s" % five
def secret_formula(started):
jelly_beans = started * 500
jars = jelly_beans / 1000
crates = jars / 100
return jelly_beans, jars, crates
# these are local variables, they are inside the function
start_point = 10000
# whatever happened to started now happens to start point
# these are global variables, they are outside the function, could be called x, y, and z
beans, jars, crates = secret_formula(start_point)
print "With a starting point of: %d" % start_point
print "We'd have %d beans, %d jars, and %d crates." (beans, jars, crates)
# reassigns with new value based on old value
start_point = start_point / 10
print "We can also do that this way:"
# brings down the info from line 29
print "We'd have %d beans, %d jars, and %d crates." % secret_formula(start_point)