首页 > 解决方案 > Python 请求 - 我开始编程

问题描述

我的请求,我开始用 Python 编程,我得到了这个请求。

直接告诉我怎么做?

编写一个程序,从用户那里获取三角形两条边的长度和它们之间的角度(以度为单位),并在此基础上计算(并显示)第三条边的长度(余弦定理),场(Heron公式或高度公式)和三角形的周长。

标签: pythonrequest

解决方案


像这样 ..

import math

#taking input from user
a = float(input('Enter first side of triangle: '))
b = float(input('Enter second side of triangle: '))
alpha = float(input('Enter angle between a and b: '))

#finding third side of triangle
c = math.sqrt((math.pow(a, 2)+math.pow(b, 2)) - 2*a*b*(math.cos(alpha)))
print('third side of triangle is: ', c)

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

print('perimeter of triangle is: ', s)

#calculate area
area = math.sqrt(s*(s-a)*(s-b)*(s-c))

print('Area of triangle is: ', area)

推荐阅读