python输出所有三位正整数中的素数,并按照一行15个输出
时间: 2024-05-04 22:15:37 浏览: 17
当然可以,以下是代码:
```python
count = 0
for num in range(100, 1000):
for i in range(2, num):
if num % i == 0:
break
else:
print(num, end=' ')
count += 1
if count % 15 == 0:
print()
```
祝您编程愉快!
相关问题
python输出所有三位正整数中的素数,按行输出
Sure, here's the code to output all prime numbers among three-digit positive integers:
```python
def is_prime(n):
if n <= 1:
return False
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return False
return True
for i in range(100, 1000):
if is_prime(i):
print(i)
```
Hope this helps!
python输出所有三位正整数中的素数,输出几行就行
Sure, here is the code to output all prime numbers among three-digit positive integers:
```
for num in range(100, 1000):
# prime numbers are greater than 1
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
```
I hope this helps!
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)