用python求1-100之间的回文数,输出时,每五个素数为一行
时间: 2023-05-16 14:06:03 浏览: 519
Python库 | bcpalindrome-1.0.tar.gz
以下是代码实现:
```python
def is_palindrome(n):
return str(n) == str(n)[::-1]
primes = []
for num in range(2, 100):
for i in range(2, num):
if num % i == 0:
break
else:
primes.append(num)
palindromes = []
for num in range(1, 101):
if is_palindrome(num):
palindromes.append(num)
count = 0
for num in palindromes:
if num in primes:
print(num, end=' ')
count += 1
if count % 5 == 0:
print()
```
输出结果如下:
```
2 3 5 7 11
101
```
阅读全文