problems with code
Steven Taschuk
staschuk at telusplanet.net
Wed May 21 22:12:07 EDT 2003
Quoth cancal:
> This script finds "Smith numbers" in the range passed to smith(). (Smith
> numbers are numbers the sum of whose digits equals the sum of digits in
> their prime factors.)
>
> At runtime a type error is raised: interation over non-sequence, at the
> line 'for each in flist' in the function pf(). pfactors() is a
> home-grown function that returns a list of the prime factors of its
> argument. It is working correctly and returning a valid list -- trust
> me. [...]
This last comment is more than a little silly. Why not just post
the code so we can see for ourselves? Especially since the
exception you report so clearly points to pfactors not returning a
list in all cases.
> [...] PF() WORKS CORRECTLY WHEN IT IS CALLED BY ITSELF. The purpose of
> pf() is to add to the list of prime factors repeated instances of the
> same factor when this is necessary for the product of all the factors to
> equal the number.
If that's its purpose, it's broken:
>>> pf(27) # should be [3, 3, 3]
[3, 9]
This error causes the code to consider 27 not a Smith number.
[...]
--
Steven Taschuk staschuk at telusplanet.net
"I tried to be pleasant and accommodating, but my head
began to hurt from his banality." -- _Seven_ (1996)
More information about the Python-list
mailing list