Python语言程序设计基础(第2版)

## P74思考与练习代码示例:
3.8 请利用math库运行下面语句,获得计算结果
1)math.sin(2*math.pi) 2) math.floor(-2.5)
3)math.ceil(3.5+math.floor(-2.5)) 4) round(math.fabs(-2.5))
5)math.sqrt(math.pow(2,4)) 6)math.log(math.e)
7) math.gcd(12,9) 8) math.fmod(36,5)
import math
>>> print(math.sin(2*math.pi))
-2.4492935982947064e-16

>>> print(math.floor(-2.5))
-3

>>> z = math.ceil(3.5+math.floor(-2.5))
>>> print(z)
1

>>> z = round(math.fabs(-2.5))
>>> print(z)
2

>>> a = math.sqrt(math.pow(2,4))
>>> print(a)
4.0

>>> s = math.log(math.e)
>>> print (s)
1.0

>>> q = math.gcd(12,9)
>>> print(q)
3

>>> print(math.fmod(36,5))
1.0

3.9 请利用math库将47°的角转换为弧度制,并将结果赋值给一个变量。

>>> import math
>>> s = math.radians(47)
>>> print(s)
0.8203047484373349

3.10 请利用math库将π/7的弧度值转换为角度值,并将结果赋值给一个变量。

>>> import math
>>> s = math.degrees(math.pi/7)
>>> print(s)
25.714285714285715

如有需要更正处,留下宝贵意见!

原创文章 27 获赞 34 访问量 2606

猜你喜欢

转载自blog.csdn.net/weixin_46313446/article/details/105326792