计算三角形面积周长
2018-02-12 13:35
399 查看
一.代码
二.运行结果
三.问题 (1) print格式控制输出
(2) 重复执行程序
四.解决
1. 打印字符串
2.打印整数
3.打印浮点数
4.打印浮点数(指定保留小数点位数)
5.指定占位符宽度
6.指定占位符宽度(左对齐)
7.指定占位符(只能用0当占位符?)
8.科学计数法
import math a=float(input("请输入三角形的边:")) b=float(input("请输入三角形的边:")) c=float(input("请输入三角形的边:")) print("三角形的三边:",a,b,c) if(a>0 and b>0 and c>0 and a+b>c and a+c>b and b+c>a): l=a+b+c h=l/2 s=math.sqrt(h*(h-a)*(h-b)*(h-c)) print("三角形的周长=%.2f,面积=%.2f"%(l,s)) else: print("无法构成三角形")
二.运行结果
请输入三角形的边:3 请输入三角形的边:4 请输入三角形的边:5 三角形的三边: 3.0 4.0 5.0 三角形的周长=12.00,面积=6.00
三.问题 (1) print格式控制输出
(2) 重复执行程序
四.解决
1. 打印字符串
print ("His name is %s"%("Aviad"))效果:
2.打印整数
print ("He is %d years old"%(25))效果:
3.打印浮点数
print ("His height is %f m"%(1.83))效果:
4.打印浮点数(指定保留小数点位数)
print ("His height is %.2f m"%(1.83))效果:
5.指定占位符宽度
print ("Name:%10s Age:%8d Height:%8.2f"%("Aviad",25,1.83))效果:
6.指定占位符宽度(左对齐)
print ("Name:%-10s Age:%-8d Height:%-8.2f"%("Aviad",25,1.83))效果:
7.指定占位符(只能用0当占位符?)
print ("Name:%-10s Age:%08d Height:%08.2f"%("Aviad",25,1.83))效果:
8.科学计数法
format(0.0015,'.2e')效果:
相关文章推荐
- 使用点类和三角形类计算三角形的周长和面积
- 计算圆面积、周长和三角形面积、周长
- C++实现计算三角形面积和周长(利用面向对象的程序设计思想)
- 第四周报告一:计算三角形的周长和面积
- 在一个图形类中计算三角形和矩形的周长和面积
- PHP图形计算器(计算三角形矩形周长面积)
- C#语言-输入三角形或者长方形边长,计算其周长和面积并输出
- 《第十五周任务一》计算三角形的面积和周长
- C++窗口程序设计(计算三角形的周长和面积)
- 第四周实验报告1(计算三角形的周长面积)
- 定义一个图形类及其子类(三角形和矩形类),分别计算面积和周长。
- 运用类来判断计算三角形周长面积
- 三角形、长方形、正方形、梯形、圆等的周长计算公式和面积计算公式
- 十五周任务1:窗口启蒙(计算三角形周长和面积)
- java用接口、多态、继承、类计算三角形和矩形周长及面积的方法
- 创建一个三角形类并且通过成员函数计算三角形的周长和面积《1》
- 创建一个三角形类并且使用成员函数计算三角形的周长和面积《2》
- 三角形、长方形、正方形、梯形、圆等的周长计算公式和面积计算公式
- 计算三角形的周长以及面积
- 创建一个几何类型类,其中有计算面积getArea()和周长getPerimeter()抽象方法,然后通过它派生出三角形类、圆形类、矩形类,并通过测试类进行测试