写一个 Python示例,如果给出两个角,用一个实例来求三角形的角。
这个 python 程序帮助用户输入三角形的两个角度。接下来,我们从 180°减去这两个角度,因为三角形中所有角度的总和= 180°。
# Python Program to find Angle of a Triangle if two angles are given
a = float(input('Please Enter the First Angle of a Triangle: '))
b = float(input('Please Enter the Second Angle of a Triangle: '))
# Finding the Third Angle
c = 180 - (a + b)
print("Third Angle of a Triangle = ", c)
这个 Python 求三角形角度的代码同上。然而,我们使用函数的概念分离了三角形的角度程序逻辑。
# Python Program to find Angle of a Triangle if two angles are given
def triangle_angle(a, b):
return 180 - (a + b)
a = float(input('Please Enter the First Angle of a Triangle: '))
b = float(input('Please Enter the Second Angle of a Triangle: '))
# Finding the Third Angle
c = triangle_angle(a, b)
print("Third Angle of a Triangle = ", c)
三角形输出的 Python 角度
Please Enter the First Angle of a Triangle: 45
Please Enter the Second Angle of a Triangle: 95
Third Angle of a Triangle = 40.0
标签: WPS