美文网首页从零开始学Python
Python习题册030:计算三角形面积

Python习题册030:计算三角形面积

作者: iLester | 来源:发表于2019-01-20 21:28 被阅读0次

任务030描述

用Python编写一个程序,由用户输入三角形的底与高,输出为三角形的面积。

分析及示例

首先可以用input()方法由用户输入表示三角形底与高的数据,再用float()转换为浮点数。而三角形的面积,可以用S= base*height/2的表达式进行计算。

示例代码:

b = float(input('please input the base:'))
h = float(input('please input the height:'))

area = b * h /2
print('area=', area)

输出结果:

please input the base:5.3
please input the height:2.6
area= 6.89

相关文章

网友评论

    本文标题:Python习题册030:计算三角形面积

    本文链接:https://www.haomeiwen.com/subject/rntzdqtx.html