小编mll*_*mll的帖子

Python pow**结果

为什么此示例中的内置运算符4**(1/2)(这是一个平方根运算)返回结果1而不是2应该预期的?如果不会返回一个可接受的结果,它应该会出错,但Python继续工作而没有任何崩溃.至少在Python 2.7.4 64位分发中.

它也会在数学函数中发生,pow(4,1/2)它返回1时没有错误.

相反,在执行4**(0.5)此操作时返回的结果2.0是正确的,尽管它混合了整数和浮点数而没有任何警告.pow也是如此.

对此行为有何解释?他们会被视为错误吗?

python python-2.7

4
推荐指数
1
解决办法
863
查看次数

在findall之后从列表中删除小于值的元素

我有:

mymake(Answer_Max):-
    findall((Place, Cost), costOfLiving(Place, Cost), ResultList),
    delete_over(ResultList, Answer_Max).
Run Code Online (Sandbox Code Playgroud)

costOfLiving 在我的数据库中,由每个地方和成本组成,例如:

costOfLiving(germany, 500).
costOfLiving(france, 500).
Run Code Online (Sandbox Code Playgroud)

等等.所以ResultList就是这样[(germany, 500), (france, 500), ...]

我想删除数据库中costOfLiving超过该数字的所有元素Answer_Max,但我的delete_over无法正常工作.它是这样的:

delete_over([], _).
delete_over([F|T], Max) :-
   F =.. [Place, Cost], % it fails here because the F is not a list, but two atoms I think
   ((id_state(Place), (Cost > Max)) -> deleteState(Place) ; true),
   % id_state and id_region checks that the place is defined in the database
   % deleteState and deleteRegion calls a …
Run Code Online (Sandbox Code Playgroud)

list prolog

0
推荐指数
1
解决办法
752
查看次数

标签 统计

list ×1

prolog ×1

python ×1

python-2.7 ×1