[Tutor] where I am going wrong?
Robert Sjoblom
robert.sjoblom at gmail.com
Wed Dec 14 16:51:51 CET 2011
surya k wrote:
> This is a project Euler puzzle. http://projecteuler.net/problem=30
> I applied brute force way and here is my codek=0for p in range(1,10): for q in range(0,10): for r in range(0,10): for s in range(0,10): for t in range(0,10): n = (p*10000)+ (q*1000) + (r*100) + (s*10) + (t*1) if n == p**5 + q**5 + r**5 + s**5 + t**5: k+=nprint kMy answer: 240559But its showing the answer as wrong!!.
> I used the same method on the example puzzle and it worked.
Your formatting is still broken, here's how I suspect you want it to look:
k=0
for p in range(1,10):
for q in range(0,10):
for r in range(0,10):
for s in range(0,10):
for t in range(0,10):
n = (p*10000)+ (q*1000) + (r*100) + (s*10) + t
if n == p**5 + q**5 + r**5 + s**5 + t**5:
#print(n)
k += n
print(k)
What Peter said is very important too. I very much doubt you'll find
the solution with those loops.
--
best regards,
Robert S.
More information about the Tutor
mailing list