[Tutor] why?
bob gailer
bgailer at gmail.com
Thu May 29 03:12:55 CEST 2008
Robert William Hanks wrote:
>
> Need ti find out whem a number o this form i**3+j**3+1 is acube.
> tryed a simple brute force code but, why this not work?
>
> def iscube(n):
> cubed_root = n**(1/3.0)
> if round(cubed_root)**3 == n:
> return True
> else:
> return False
>
> for i in range(1,10000000):
> for j in range(1,10000000):
> soma= i**3 +j**3 +1
> if isCube(soma):
> print i
> print j
> print soma
>
>
Always report the specific problem. Saying "why this not work?" does not
help.
What happens when you run this program?
When I do I get:
File "J:\pipelines\cubed.py", line 11, in <module>
if isCube(soma):
NameError: name 'isCube' is not defined
When I examine the program I'm not surprised to get that exception.
--
Bob Gailer
919-636-4239 Chapel Hill, NC
More information about the Tutor
mailing list