python输出所有三位正整数中的素数
时间: 2024-05-14 10:13:41 浏览: 73
Sure, here's the code:
```python
for i in range(100, 1000):
is_prime = True
for j in range(2, i):
if i % j == 0:
is_prime = False
break
if is_prime:
print(i)
```
I hope that helps!
相关问题
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!
阅读全文