print ("abs(-40) : ", abs(-40)) print ("abs(100.10) : ", abs(100.10))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.ceil(-45.17) : ", math.ceil(-45.17)) print ("math.ceil(100.12) : ", math.ceil(100.12)) print ("math.ceil(100.72) : ", math.ceil(100.72)) print ("math.ceil(math.pi) : ", math.ceil(math.pi))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.exp(-45.17) : ", math.exp(-45.17)) print ("math.exp(100.12) : ", math.exp(100.12)) print ("math.exp(100.72) : ", math.exp(100.72)) print ("math.exp(math.pi) : ", math.exp(math.pi))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.fabs(-45.17) : ", math.fabs(-45.17)) print ("math.fabs(100.12) : ", math.fabs(100.12)) print ("math.fabs(100.72) : ", math.fabs(100.72)) print ("math.fabs(math.pi) : ", math.fabs(math.pi))
#!/usr/bin/python import math # 导入 math 模块 print ("math.floor(-45.17) : ", math.floor(-45.17)) print ("math.floor(100.12) : ", math.floor(100.12)) print ("math.floor(100.72) : ", math.floor(100.72)) print ("math.floor(math.pi) : ", math.floor(math.pi))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.log(100.12) : ", math.log(100.12)) print ("math.log(100.72) : ", math.log(100.72)) print ("math.log(math.pi) : ", math.log(math.pi))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.log10(100.12) : ", math.log10(100.12)) print ("math.log10(100.72) : ", math.log10(100.72)) print ("math.log10(119) : ", math.log10(119)) print ("math.log10(math.pi) : ", math.log10(math.pi))
#!/usr/bin/python3 print ("max(80, 100, 1000) : ", max(80, 100, 1000)) print ("max(-20, 100, 400) : ", max(-20, 100, 400)) print ("max(-80, -20, -10) : ", max(-80, -20, -10)) print ("max(0, 100, -400) : ", max(0, 100, -400))
#!/usr/bin/python3 print ("min(80, 100, 1000) : ", min(80, 100, 1000)) print ("min(-20, 100, 400) : ", min(-20, 100, 400)) print ("min(-80, -20, -10) : ", min(-80, -20, -10)) print ("min(0, 100, -400) : ", min(0, 100, -400))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.modf(100.12) : ", math.modf(100.12)) print ("math.modf(100.72) : ", math.modf(100.72)) print ("math.modf(119) : ", math.modf(119)) print ("math.modf(math.pi) : ", math.modf(math.pi))
#!/usr/bin/python3 print ("round(70.23456) : ", round(70.23456)) print ("round(56.659,1) : ", round(56.659,1)) print ("round(80.264, 2) : ", round(80.264, 2)) print ("round(100.000056, 3) : ", round(100.000056, 3)) print ("round(-100.000056, 3) : ", round(-100.000056, 3))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.pow(100, 2) : ", math.pow(100, 2)) # 使用内置,查看输出结果区别 print ("pow(100, 2) : ", pow(100, 2)) print ("math.pow(100, -2) : ", math.pow(100, -2)) print ("math.pow(2, 4) : ", math.pow(2, 4)) print ("math.pow(3, 0) : ", math.pow(3, 0))
#!/usr/bin/python3 import math # 导入 math 模块 print ("math.sqrt(100) : ", math.sqrt(100)) print ("math.sqrt(7) : ", math.sqrt(7)) print ("math.sqrt(math.pi) : ", math.sqrt(math.pi))
#!/usr/bin/python3 import random print ("从 range(100) 返回一个随机数 : ",random.choice(range(100))) print ("从列表中 [1, 2, 3, 5, 9]) 返回一个随机元素 : ", random.choice([1, 2, 3, 5, 9])) print ("从字符串中 'Runoob' 返回一个随机字符 : ", random.choice('Runoob'))
#!/usr/bin/python3 #!/usr/bin/python3 import random # 从 1-100 中选取一个奇数 print ("randrange(1,100, 2) : ", random.randrange(1, 100, 2)) # 从 0-99 选取一个随机数 print ("randrange(100) : ", random.randrange(100))
#!/usr/bin/python3 import random # 第一个随机数 print ("random() : ", random.random()) # 第二个随机数 print ("random() : ", random.random())
#!/usr/bin/python3 import random random.seed() print ("使用默认种子生成随机数:", random.random()) random.seed(10) print ("使用整数种子生成随机数:", random.random()) random.seed("hello",2) print ("使用字符串种子生成随机数:", random.random())
#!/usr/bin/python3 import random list = [20, 16, 10, 5]; random.shuffle(list) print ("随机排序列表 : ", list) random.shuffle(list) print ("随机排序列表 : ", list)
#!/usr/bin/python3 import random print ("uniform(5, 10) 的随机浮点数 : ", random.uniform(5, 10)) print ("uniform(7, 14) 的随机浮点数 : ", random.uniform(7, 14))
#!/usr/bin/python3 import math print ("acos(0.64) : ", math.acos(0.64)) print ("acos(0) : ", math.acos(0)) print ("acos(-1) : ", math.acos(-1)) print ("acos(1) : ", math.acos(1))
#!/usr/bin/python3 import math print ("asin(0.64) : ", math.asin(0.64)) print ("asin(0) : ", math.asin(0)) print ("asin(-1) : ", math.asin(-1)) print ("asin(1) : ", math.asin(1))
#!/usr/bin/python3 import math print ("atan(0.64) : ", math.atan(0.64)) print ("atan(0) : ", math.atan(0)) print ("atan(10) : ", math.atan(10)) print ("atan(-1) : ", math.atan(-1)) print ("atan(1) : ", math.atan(1))
#!/usr/bin/python3 import math print ("atan2(-0.50,-0.50) : ", math.atan2(-0.50,-0.50)) print ("atan2(0.50,0.50) : ", math.atan2(0.50,0.50)) print ("atan2(5,5) : ", math.atan2(5,5)) print ("atan2(-10,10) : ", math.atan2(-10,10)) print ("atan2(10,20) : ", math.atan2(10,20))
#!/usr/bin/python3 import math print ("cos(3) : ", math.cos(3)) print ("cos(-3) : ", math.cos(-3)) print ("cos(0) : ", math.cos(0)) print ("cos(math.pi) : ", math.cos(math.pi)) print ("cos(2*math.pi) : ", math.cos(2*math.pi))
#!/usr/bin/python3 import math print ("hypot(3, 2) : ", math.hypot(3, 2)) print ("hypot(-3, 3) : ", math.hypot(-3, 3)) print ("hypot(0, 2) : ", math.hypot(0, 2))
#!/usr/bin/python3 import math print ("sin(3) : ", math.sin(3)) print ("sin(-3) : ", math.sin(-3)) print ("sin(0) : ", math.sin(0)) print ("sin(math.pi) : ", math.sin(math.pi)) print ("sin(math.pi/2) : ", math.sin(math.pi/2))
#!/usr/bin/python3 import math print ("(tan(3) : ", math.tan(3)) print ("tan(-3) : ", math.tan(-3)) print ("tan(0) : ", math.tan(0)) print ("tan(math.pi) : ", math.tan(math.pi)) print ("tan(math.pi/2) : ", math.tan(math.pi/2)) print ("tan(math.pi/4) : ", math.tan(math.pi/4))
#!/usr/bin/python3 import math print ("degrees(3) : ", math.degrees(3)) print ("degrees(-3) : ", math.degrees(-3)) print ("degrees(0) : ", math.degrees(0)) print ("degrees(math.pi) : ", math.degrees(math.pi)) print ("degrees(math.pi/2) : ", math.degrees(math.pi/2)) print ("degrees(math.pi/4) : ", math.degrees(math.pi/4))
#!/usr/bin/python3 import math print ("radians(3) : ", math.radians(3)) print ("radians(-3) : ", math.radians(-3)) print ("radians(0) : ", math.radians(0)) print ("radians(math.pi) : ", math.radians(math.pi)) print ("radians(math.pi/2) : ", math.radians(math.pi/2)) print ("radians(math.pi/4) : ", math.radians(math.pi/4))