Moving along, here! This lesson was mostly a refresher on function ordering, for me. At the very end, there is an extra credit portion where he recommends resolving a nested set of functions by hand before running the program.
print "Here is a puzzle."
age = add(30, 5)
height = subtract(78, 4)
weight = multiply(90, 2)
iq = divide(100, 2)
what = add(age, subtract(height, multiply(weight, divide(iq, 2))))
print "That becomes: ", what, "Can you do it by hand?"
I knew that it was necessary to resolve inner parentheses before moving on to the next inner set of parentheses as just a giant composed function, but once I got to the non-commutative operations (ie, subtraction and division, in which order of operation matters) I flubbed it up a bit, and came up with a different answer than when I ran the program. Then I examined it a bit, and with a bit more analysis (that’s an overly heady word for it, ha ha!) in the form of the following:
age = add(30, 5) #35
height = subtract(78, 4) #74
weight = multiply(90, 2) #180
iq = divide(100, 2) #50
and then resolved the commutativity issue, I came up with the same answer that he did! woo-hoo!
Woo-hoo! Another lesson down!