frustrated stupid newbie question

Brian brian at lodoss.org
Wed Mar 13 01:17:14 EST 2002


Scott,

Someone already pointed out the off by 1 error, but there's something
else that's getting you as well:

...
if number/checking == int(number/checking):
...

In your code, neither number or checking are floats; the result of
number/checking is not a float.

I'm still pretty new at Python myself, so there's probably a simpler
way to do this, but changing one of the ranges to floats:

>>> for number in range(1,50):
	number = float(number)
	factorsum = 0
	halfnumber = number / 2
	for checking in range(1,halfnumber+1):
		if number/checking == round(number/checking):
			factorsum = factorsum + checking
	if number == factorsum:
		print number

		
6.0
28.0
>>> 
...seems to produce the result you were looking for.



More information about the Python-list mailing list