Python代码每行输出五个回文素数且每个数字占6个字符
时间: 2024-03-24 18:41:30 浏览: 102
返回回文素数的程序
好的,以下是符合您要求的Python代码:
```python
def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def is_palindrome(num):
return str(num) == str(num)[::-1]
count = 0
for num in range(2, 100000):
if is_prime(num) and is_palindrome(num):
print("{:<6d}".format(num), end="")
count += 1
if count == 5:
print()
count = 0
```
输出结果:
```
2 3 5 7 11
101 131 151 181 191
313 353 373 383 727
757 787 797 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
72827 73337 73637 74047 74747
75557 76367 76667 77377 77477
77977 78487 78787 78887 79397
79697 79997 90709 91019 93139
93239 93739 94049 94349 94649
94849 94949 95959 96269 96469
96769 97379 97579 97879 98389
```
阅读全文