请问一下py里面打印前一百个回文素数 打印十个换行应该怎么写
2条回答 默认 最新
关注
def isPrime(n): for i in range(2,n): if n%i == 0: return False return True def isPalindrome(n): t = str(n) if t == t[::-1]: return True return False num, count = 1, 0 while count<100: num += 1 if isPalindrome(num) and isPrime(num): count += 1 print(num, end = '\t' if count%10 else '\n')
2 3 5 7 11 101 131 151 181 191
313 353 373 383 727 757 787 797 919 929
10301 10501 10601 11311 11411 12421 12721 12821 13331 13831
13931 14341 14741 15451 15551 16061 16361 16561 16661 17471
17971 18181 18481 19391 19891 19991 30103 30203 30403 30703
30803 31013 31513 32323 32423 33533 34543 34843 35053 35153
35353 35753 36263 36563 37273 37573 38083 38183 38783 39293
70207 70507 70607 71317 71917 72227 72727 73037 73237 73637
74047 74747 75557 76367 76667 77377 77477 77977 78487 78787
78887 79397 79697 79997 90709 91019 93139 93239 93739 94049本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 2无用 1