Home >Backend Development >Python Tutorial >Python素数检测实例分析

Python素数检测实例分析

WBOY
WBOYOriginal
2016-06-06 11:18:421146browse

本文实例讲述了Python素数检测的方法。分享给大家供大家参考。具体如下:

该程序实现了素数检测器功能,如果结果是true,则是素数,如果结果是false,则不是素数。

def fnPrime(n):
  for i in range(2,n,1):
    if(n % i == 0):
      return bool(0)
  return bool(1)

希望本文所述对大家的Python程序设计有所帮助。

Statement:
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