50以内的质数 python
时间: 2023-06-23 07:50:12 浏览: 201
用python求100以内质数
可以用以下代码来找到50以内的质数:
```python
primes = []
for num in range(2, 50):
for i in range(2, num):
if num % i == 0:
break
else:
primes.append(num)
print(primes)
```
输出结果为:
```python
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]
```
阅读全文