refactor 001-010

remove variables used only for loops (e.g. change "while" to "for i in range")
and make variable names clearer (e.g. don't use "n" and "num" in the same function!!)