[Tutor] Project Euler Problem 6
joe gallo
gallo.j at gmail.com
Thu Apr 24 22:22:45 CEST 2008
It says: Find the difference between the sum of the squares of the first *
one
hundred* natural numbers and the square of the sum.
You did range(1,111).
On Thu, Apr 24, 2008 at 1:13 PM, kinuthia muchane <muchanek at gmail.com>
wrote:
> Hi,
>
> I am trying to solve problem 6 on the Project Euler, but when I submit
> my answer, I am told that it is wrong. Here is the problem:
>
>
> The sum of the squares of the first ten natural numbers is,
>
>
> 1² + 2² + ... + 10² = 385
> The square of the sum of the first ten natural numbers is,
>
>
> (1 + 2 + ... + 10)² = 55² = 3025
> Hence the difference between the sum of the squares of the first ten
> natural numbers and the square of the sum is 3025 − 385 = 2640.
>
> Find the difference between the sum of the squares of the first one
> hundred natural numbers and the square of the sum.
>
> And here is my code:
>
> def aux():
> return sum([k*k for k in range(1,111)])# sum of the squares of the
> first one hundred numbers
>
> def aux1():
> inter = sum([k for k in range(1,111))# square of the sum of the
> first
> one hundred numbers
> return inter**2
>
> def aux2():
> return aux1() - aux()# the difference of the two sums
>
> print aux2()
>
> ...which gives a result of 36821290.
>
> It worked fine with the example they have given but not with the hundred
> one... What am I missing?
>
> Thanks!
> Kinuthia...
>
>
>
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080424/5d5e1fb3/attachment.htm>
More information about the Tutor
mailing list