So my son had math homework on determining the factors of numbers. This was part of a larger mondule on factors, prime, and composite numbers. So after completing the homework together I asked him: "Do you think we can modify our times table program to calculate the factors of a number?".
He thought for a moment and then said: "Yes".
And so we set to it. As it turns out, the program required little change, but the significant new piece of learning was the moduls operator.
We essentially looped from 1 to the given number and took the modulus of the given number by the loop iteration. If the modulus had a value, then the loop iteration was not a factor. If there was no remainder, then it was a factor, which we would print.
Of course this also introduced to him the concept of the if test statement in python.
Showing posts with label if. Show all posts
Showing posts with label if. Show all posts
Subscribe to:
Posts (Atom)