I created a Python script to find two whole numbers that, when multiplied together, will equal the target number, or factors. My script works by dividing the target number by a regularly increasing integer, and checking to see if the quotient is a whole number (integer).
Here's the script:
#!/usr/bin/python cnum = 21 cntnu = 1 currint = 1 #Begin Loop while cntnu == 1: currint = currint + 1 oput = cnum/currint if type(oput) == type(1): cntnu = 0 print "Factorization Found." print oput print "x" print currint else: print "Factorization failed. Trying next factorization..." #End Loop
However, when I run this I get this output:
Factorization Found. 10 x 2
Obviously, not 21.
What am I doing wrong?
Thanks in advance!