Python请求我开始编程

2024-05-20 15:47:05 发布

您现在位置:Python中文网/ 问答频道 /正文

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

告诉我怎么做

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


Tags: 用户程序高度编程单位公式角度三角形
2条回答

作为一个新的程序员,我知道如何使程序取两个数字,我有问题,这个程序应该如何取90度角

a = float(input("first side")) b = float(input("second side")) x = float(input("degree angle"))

程序如何计算第三方(c)

像这样

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)

相关问题 更多 >