请编写程序判断一个数是否素数的平方
如:25是5的平方,符合题意,24不合题意
"""
name: wzl
date: 2020/2/27
task: 24. 请编写程序判断一个数是否素数的平方
如:25是5的平方,符合题意。24不合题意。
"""
from math import *
def is_prim(num): #判断素数
is_prime = True
for i in range(2,int(sqrt(num))+1):
if num%i==0:
is_prime = False
break
if is_prime and num>1:
return True
else:
return False
if __name__=='__main__':
x = int(input('please enter the number to be tested: '))
y = sqrt(x)
if int(y) == y:
if is_prim(y)== True:
print('{}={}^^2'.format(x,int(y)))
else:
print('nope')
else:
print('nope')
please enter the number to be tested: 64
nope
please enter the number to be tested: 25
25=5^^2