判断是否为素数

方法一
data=https://www.it610.com/article/int(input("please input a number:"))
if data=https://www.it610.com/article/=1:
print(data,"is not a prime number")
if data=https://www.it610.com/article/=2:
print(data,"is a prime")
for i in range(2,data):
if data%i==0:
print(data,"is not a prime")
break
if i==data-1:
print(data,"is a prime number")
【判断是否为素数】方法2
#coding=utf-8
#使用函数sqrt()判断一个数字是否是素数
import math
def is_prime(num):
if not isinstance(num,int):
return false
for i in range(2,int(math.sqrt(num)+1)):
if num%i ==0:
return False
else:
return True

    推荐阅读