📜  Python 三角形计算

📅  最后修改于: 2020-10-30 00:45:17             🧑  作者: Mango

Python程序找到三角形的面积

数学公式:

三角形的面积=(s *(sa)*(sb)*(sc))-1/2

s是半周长,a,b和c是三角形的三个边。

请参阅以下示例:

# Three sides of the triangle is a, b and c:
a = float(input('Enter first side: '))
b = float(input('Enter second side: '))
c = float(input('Enter third side: '))

# calculate the semi-perimeter
s = (a + b + c) / 2

# calculate the area
area = (s*(s-a)*(s-b)*(s-c)) ** 0.5
print('The area of the triangle is %0.2f' %area) 

输出:

注意:%0.2f浮点数指定小数点后至少0个宽度和2个数字。如果使用%0.5f,则它将在小数点后给出5个数字。

请参阅以下示例: