我今天的问题是,我是否正在为 Euler 145 走上正确的道路,以及它是否有点有效。我已经完成了大部分工作,只有我的一个 Defs 给我带来了麻烦 int(str(numb)[:i])%2==0 进行偶数检查。我的代码如下。第 10 行是问题点
def reversed(reg): # to flip the number around
fliped = str(reg)[::-1];
return(int(fliped)); # Return it as a int.
def allEvenDigits(numb): # This is the issue one
hasEvenNumb = False;
for i in range(0, len(str(numb))):
if int(str(numb)[:i])%2 == 0: # if int of the string numb's char at i is even
hasEvenNumb = True; ## return that it is true
break; # why go on if we found a even.
return(hasEvenNumb);
for i in range(1, 1000): # its 1000 to save a few minutes
revNumb = reversed(i);
total = revNumb+i;
if(allEvenDigits(total)):
print(i, "+" , revNumb, "=",Total);