在python编程语言中 , 数学模块中定义了一些内置函数–它们可用于三角函数计算,python具有以下三角函数,可用于各种用途。

 

Python中的三角函数列表

 

Python代码演示所有三角函数的示例

# Python code to demonstrate example 
# of all Trigonometric functions
 
# importing math module
import math
 
# number 
x = 0.75 
 
# math.cos()
print("math.cos(",x,"): ", math.cos(x));
# math.sin()
print("math.sin(",x,"): ", math.sin(x));
# math.tan()
print("math.tan(",x,"): ", math.tan(x));
 
# math.acos()
print("math.acos(",x,"): ", math.acos(x));
# math.asin()
print("math.asin(",x,"): ", math.asin(x));
# math.atan()
print("math.atan(",x,"): ", math.atan(x));
 
y = 2
# math.atan2(y,x) = atan(y/x)
print("math.atan2(",y,",",x,"): ", math.atan2(y,x))
 
# math.hypot(x,y)
print("math.hypot(",x,",",y,"): ", math.hypot(x,y))

输出量

math.cos( 0.75 ):  0.7316888688738209
math.sin( 0.75 ):  0.6816387600233341
math.tan( 0.75 ):  0.9315964599440725
math.acos( 0.75 ):  0.7227342478134157
math.asin( 0.75 ):  0.848062078981481
math.atan( 0.75 ):  0.6435011087932844
math.atan2( 2 , 0.75 ):  1.2120256565243244
math.hypot( 0.75 , 2 ):  2.1360009363293826

 

使用Python计算三角形的周长和面积(海伦公式)

import math
a=int(input("请输入三角形的第一条边"))
b=int(input("请输入三角形的第二条边"))
c=int(input("请输入三角形的第三条边"))
zc,mj,s=0,0,0
if a+b>c and a+c>b and b+c>a:
    zc=a+b+c
    p=zc/2
    mj=(p*(p-a)*(p-b)*(p-c))**(1/2)
    zc=str(zc)
    mj=str(mj)
    print("该三角形的周长为" + zc)
    print("该三角形的面积为" + mj)
else:
    print("无法构成三角形!")