gpt4 book ai didi

python - 我怎么能说一个数字是否自然返回真?

转载 作者:太空宇宙 更新时间:2023-11-04 11:09:41 25 4
gpt4 key购买 nike

如何写“如果数字自然返回真”?我

我试过命令 int 和 float 但它对我没有帮助

def perfectsquareroot(a):
import math
x=math.sqrt(a)
if x is int
return True
else
return False

如果平方根的结果不是自然数,我希望返回 false

最佳答案

def perfectsquareroot(a):
import math
x=math.sqrt(a)
return x == int(x)

关于python - 我怎么能说一个数字是否自然返回真?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58596778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com