python 3.1.6
pycharm
import math # 数学相关功能import random # 随机数相关功能
a = math.ceil(4.01) # 上行取整print(a, type(a))
a = math.floor(3.4) # 下行取整print(a, type(a))
# 将浮点数的小数部分和整数部分分开,返回结果是一个容器,可以用批量赋值的方式接收。a, b = math.modf(34.78)print(a, b)
print('%.29f' % math.pi) # math.pi 圆周率print(math.sqrt(5)) # 开根,结果会忽略负数
print('*******************随机数*********************')# range(1, 100, 3) 代表一个数列区间print(list(range(9))) # 查看区间中所有元素
a = random.choice(range(10, 0, -1)) # 从10开始间隔为-1的数列中随机出一个数字b = random.choice(range(1, 11))print(a, b)
a = random.choice('我爱中国') # 从字符串中随机出一个字符print(a, type(a))a = random.randrange(1, 9, 3) # 相当于:random.choice(range(1, 9, 3))print(a)a = random.random() # 随机一个0到1之间的浮点数print(a)
# 20-29a = int(random.random()*10) + 20print(a)print(random.uniform(4, 9)) # 2数之间随机出一个浮点数
# 号后面的文字为注释