码迷,mamicode.com
首页 > 编程语言 > 详细

由python的math.log想到的问题

时间:2017-06-30 15:45:03      阅读:208      评论:0      收藏:0      [点我收藏+]

标签:不清楚   math   多少   nbsp   技术分享   python   idt   bsp   image   

 

result = math.log(243,3)

print(result) 输出5.0

print("%f"%result) 还是输出5.0

 

技术分享技术分享

 

看出问题了吗?对,没错。int(5.0) = 4?????

 

不只是这个,还有取余

技术分享

技术分享

5.0 mod 1 为 1?????

 

经过和同学的激烈讨论。

得出了这么一个结论。

其实result = math.log(243,3) ,返回的result是4.9999(具体多少个9)不清楚,总之不是我们觉得应该的5。

技术分享技术分享

 

所以可以解答上面的疑惑了。

1、int(result)其实是int(4.999.。。) = 4

2、result%1 其实是 4 余 0.999.。。

 

但是 无论你是格式化输出还是print 0.9999。。。输出是1

4.999.。。。。输出是5.

 

由python的math.log想到的问题

标签:不清楚   math   多少   nbsp   技术分享   python   idt   bsp   image   

原文地址:http://www.cnblogs.com/wzben/p/7098558.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!