# Functions can return

# Ok, Dawn this is another step forward

# Towards a good success I guess ðŸ™‚

# In here, we introduce a new Python word ‘return’

def add(a, b):

print “\nADDING %d + %d” % (a, b)

return a + b

def subtract(a, b):

print “\nSUBTRACTING %d – %d” % (a, b)

return a- b

def multiply(a, b):

print “\nMULTIPLYING %d * %d” % (a, b)

return a * b

def divide(a, b):

print “\nDIVIDING %d / %d” % (a, b)

return a / b

def node(a, b): # This is Dawn at work

print “\nNode %d > %d” % (a, b)

print 87 > 7

return a / b

print “Let’s do some math with just functions!”

node = node(87, 7)

age = add(30, 5)

height = subtract(78,4)

weight = multiply(90, 2)

iq = divide(100, 2)

print “Noded: %d” % (node)

print “Age: %d, Height: %d, Weight: %d, IQ: %d” % (age, height, weight, iq)

# A puzzle for the extra credit, type it in anyway.

print “Here is a puzzle.”

what = add(age, subtract(height, multiply(weight, divide(iq, 2))))

print “That becomes: “, what, “Can you do it by hand?”

# Ok, Dawn so here we dissolves the puzzle

what0 = divide(50, 2)

what1 = multiply(180, 25)

what2 = subtract(74, 4500)

what3 = add(35, -4426)

print “That becomes: “, what0 + what1 + what2 + what3, “Puzzled dissolved?”

raw_input (“\n>>> “)

hi = subtract(10, 100)

print “Hi is used and there is some subtraction which is “, hi, “or?”

### Like this:

Like Loading...