<分区>
我的代码是
if graph == square_grid and type(math.sqrt(nodes)) is not int:
print "Your netork can't have that number of nodes"
当然这是行不通的,因为 math.sqrt 总是返回一个 float 。我该怎么做?
标签 python
<分区>
我的代码是
if graph == square_grid and type(math.sqrt(nodes)) is not int:
print "Your netork can't have that number of nodes"
当然这是行不通的,因为 math.sqrt 总是返回一个 float 。我该怎么做?
最佳答案
一种方式是
int(math.sqrt(x)) ** 2 == x
关于python - 如何在 Python 中测试一个数字是否为平方数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16426396/
相关文章:
python - 使用 firebase_admin 或 google.cloud.firestore 在 python 中的 Firestore 客户端(作为用户)
python - Django updateview 表单验证错误未显示在模板中
python - 添加两个未正确计算的 __init__ 变量(应该很简单解决,我是类的菜鸟)
python - 如何加快访问 pandas 数据框列中的字典列表?
python - Pygame "No module called pygame.base"