Re: Exercise 3: Numbers And Math — Learn Python The Hard Way, 2nd Edition - http://learnpythonthehardway.org/book...
Feb 12, 2012
from
"A lot of people are having problems with the order in which the arithmetic will occur (i.e. the order of the operators). When using other languages, I almost always use parenthesis to demonstrate to people reading the code (and to the interpreter / compiler) the order in which I want the arithmetic to occur... i.e.
print "Hens", 25 + 30 / 6
print "Hens", 25 + (30 / 6)
print "Roosters", 100 - 25 * 3 % 4
print "Roosters", 100 - ((25 * 3) % 4)
PS Thanks to Fernando for PEDMAS - I've been programming (and occasionally teaching programming) since last century and never came across that before.
PPS and thanks to Zedshaw, for an excellent resource"
- martin english