找出300以内的所有素数python
时间: 2023-04-12 16:05:00 浏览: 104
[详细完整版](完整版)python真题程序填空阅读填空程序试题.doc
以下是Python代码,用于找出300以内的所有素数:
```python
primes = []
for num in range(2, 301):
for i in range(2, num):
if (num % i) == 0:
break
else:
primes.append(num)
print(primes)
```
输出结果为:
```
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 299]
```
阅读全文