I think your code is fine - although you can optimize it, of course.
But I guess the main problem is that SPOJ returns NZEC error for situations where TLE would be correct. Really misleading. I submitted this code
while True:
pass
and got NZEC
And there is a good chance that your code is too slow to finish within time limit, since you picked (once again) a problem where all succesfull python submissons used Psyco (you can detect this by the memory usage > 36M) which is no longer available on this server.
If you want to get an idea which problem can be solved using python, have a look at numerix' or mine submissions.