1.输入三角形的三边长a、b、c,输出三角形的面积。
a = float(input('输入三角形第一边长: '))
b = float(input('输入三角形第二边长: '))
c = float(input('输入三角形第三边长: '))
s = (a + b + c) / 2
area = (s * (s - a) * (s - b) * (s - c))/2
print('三角形面积为 %0.2f' % area)
运行结果:
2.输入圆的半径,求圆的周长和面积。
import math
# 输入部分
r = float(input('输入圆的半径:'))
# 处理部分
c = 2 * math.pi * r
s = math.pi * r ** 2
# 输出部分
print('该圆的周长是:%.2f' % c)
print('该圆的面积是:%.2f' % s)
运行结果: