Home > Backend Development > Python Tutorial > python求素数示例分享

python求素数示例分享

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:45:15
Original
1259 people have browsed it

复制代码 代码如下:

# 判断是否是素数
def is_sushu(num):
 res=True
 for x in range(2,num-1):
  if num%x==0:
   res=False
   return res
 return res

# 打印出素数列表
print ([x for x in range(1000) if is_sushu(x)])

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template