如何测试Python中的数字是否为正方形?
发布时间:2020-12-20 13:01:26 所属栏目: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总是返回一个浮点数.我怎样才能做到这一点? 解决方法 一种方法是 int(math.sqrt(x)) ** 2
我的代码是
if graph == square_grid and type(math.sqrt(nodes)) is not int: print "Your netork can't have that number of nodes" 当然这不起作用,因为math.sqrt总是返回一个浮点数.我怎样才能做到这一点? 解决方法
一种方法是
int(math.sqrt(x)) ** 2 == x (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |