python - Python 请求 - 我开始编程
问题描述
我的请求,我开始用 Python 编程,我得到了这个请求。
直接告诉我怎么做?
编写一个程序,从用户那里获取三角形两条边的长度和它们之间的角度(以度为单位),并在此基础上计算(并显示)第三条边的长度(余弦定理),场(Heron公式或高度公式)和三角形的周长。
解决方案
像这样 ..
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)
推荐阅读
- javascript - 如何在 ECharts 中为图形制作动画
- c++ - Is it safe to cast a class to a derived class that just adds additional functions?
- java - 声纳错误:使用 try-with-resources 或在“finally”子句中关闭此“ZipOutputStream”
- java - Spring Boot 2.5 加载Schema.sql 无效SQL语句
- reactjs - Ag-grid 使用服务器端行模型和部分行存储时如何添加新行
- c# - 如何使用 CSVHelper 更新现有 CSV 文件中特定列中的值?
- react-native - 如何在反应导航中用深层链接替换现有屏幕
- css - AntDVue ant-collapse 用干净的 CSS 改变箭头的方向
- json - Ansible 正在自动将字符串 (json) 转换为具有新效果的 dict?
- c# - Umbraco IContent GetValue 始终为空