《Python核心编程》第二版第97页第五章练习 续二

《Python核心编程》第二版第97页第五章练习
和大家分享自己完成的《Python核心编程》答案。
因为不是来自官方资源,是自己的的练习,可能有误或者并非最好的解决办法。

【推荐】晒一晒一个程序员《读过的好书》
http://debug-sai.blogbus.com/logs/42178629.html

5-8.
几何。计算面积和体积。
(a)正方形和立方体
(b)圆和球
【答案】
代码如下:
a = float(raw_input('Please input a numner: ... '))
print 'If this is a side length of a square ...'
print '... the acreage of this square is %f' % (a * a)
print 'If this is a side length of a cube ...'
print '... the cubage of this cube is %f' % (a * a * a)
print 'If this is a radii of a circularity ...'
print '... the acreage of this circularity is %f' % (3.14159 * a * a)
print 'If this is a radii of a sphere ...'
print '... the cubage of this sphere is %f' % (3.14159 * a * a * a * 4 / 3)

【参考】用Python做科学计算
http://hyry.dip.jp/pydoc/index.html#
一篇推荐这个网站的文章
http://blog.sina.com.cn/s/blog_4b5039210100mrdl.html
怎样用Python计算圆周率
http://my.opera.com/yunt/blog/show.dml/295271

5-9.
数值形式回答下面关于数值格式的问题:
(a)为什么下面的例子里17+32等于49,而017+32等于47,017+032等于41?
>>> 17 + 32
49
>>> 017 + 32
47
>>> 017 + 032
41
(b)为什么下面这个表达式我们得到的结果是134L而不是1342?
>>> 56l + 78l
134L
【答案】
(a)因为Python中0开头的数字表示八进制数。八进制数017表示15,而八进制数032表示26,所以得到如题所示答案。
(b)561加上781才是1342,而56l加上78l是134L。

原文地址:https://www.cnblogs.com/balian/p/1946926.html