数学函数

# 基础的数学函数

# 1、绝对值 ads(x) 返回x的整行绝对值

fl=abs(10)
print(fl)#10
f2=abs(-10)
print(f2)#10

# 2、比较两个数字的大小(x>y)-(x<y)
# 当x大,返回1;当x等于y,返回0;当x小返回-1
# 假设x大:x > y ==> True 1    x < y ==> False 0  1-0=1
# 假设x小:x > y ==> False 0    x < y ==> True 1   0-1=-1
# 假设x==y:x > y ==> False 0    x < y ==> False 0   0-0=0
print("------分割线")
a=20
b=10
res=(a>b)-(a<b)
print(res)

# 返回最大值或最小值 max(x1,x2,x3....) min(x1,x2,x3..)
maxRes = max(1,2,3,4,5)
print(maxRes)
minRes=min(1,2,4,5,6)
print(minRes)

# 返回x的y次幂 pow(x,y)
powres =pow(2,3)
print(powres)


# 返回x的四舍六人值
# 语法格式:round(x,[,n]) n代表保留几位小数
# 当距离两边的整数大小相同时(数字5),结果取偶不取奇
num1=round(3.4)
print(num1)
num2=round(3.5)
print(num2)
num3=round(3.6)
print(num3)
num5=round(3.51)
print(num3)
num4=round(3.1415926,5)
print(num4)
原文地址:https://www.cnblogs.com/BKY88888888/p/11252281.html