frustrated stupid newbie question

Nick nick at nick8325.freeserve.co.uk
Tue Mar 12 18:13:21 EST 2002


"Scott Kurland" <skurland at juggler.net> wrote in message
news:u8t22ns5jo7i46 at corp.supernews.com...
> Why isn't this $%^*#$% program working?
>
> #Searching for perfect numbers
>
> howhigh= input ("How high should I check?")
> for number in range (1,howhigh):
>  factorsum = 0
>  halfnumber=number/2
>  for checking in range (1,halfnumber):
>   if number/checking == int (number/checking):
>    factorsum = factorsum + checking
>  if number == factorsum:
>   print number
>
>

Err, well I'm a newbie myself, but it seems to work if you replace
range(1,halfnumber) with range(1,halfnumber+1). This may be because you are
using floating point arithmetic - maybe Python is storing halfnumber,
instead of, e.g. 2, as 1.99999 etc.

>
> Flame away, I can't feel dumber than this.
>
> --
> "Quemadmodum gladius neminem occidit, occidentis telum est."
> -- Seneca
>
>
>





More information about the Python-list mailing list