我在写一个程序,告诉你一个数是不是质数。给你。正如您在运行chkPrime函数时看到的,所有操作都返回true。我一辈子都搞不懂。有什么想法吗?在total=0
#Check if number is whole
def chkWhole(x):
if(x%1 == 0):
return True
else:
return False
#Check to see if the number divides evenly with all primes
def chkModtwo(n):
a=n%2
if chkWhole(a)==True:
return True
else:
return False
def chkModthree(n):
a=n%3
if chkWhole(a)==True:
return True
else:
return False
def chkModfive(n):
a=n%5
if chkWhole(a)==True:
return True
else:
return False
def chkModseven(n):
a=n%7
if chkWhole(a)==True:
return True
else:
return False
#Check if the number is a prime using other two functions
def chkPrime(n):
if n== 1 or 2 or 3 or 5 or 7:
return True
if chkModtwo(n)==False and chkModthree(n)==False and chkModfive(n)==False and chkModseven(n)==False:
return True
else:
return False
#while True:
#yourinput=raw_input("Enter to check if it is a prime")
#
#
# youranswer=chkPrime(yourinput)
#
# if youranswer==True:
# print("Yes, it is a prime")
# else:
# print("No, this number is not prime")