import math
def circle_area(radius):
return math.pi * radius * radius
def circle_perimeter(radius):
return math.pi * radius * 2
rad = float(input("请输入圆的半径: "))
if rad <= 0:
print("请输入,有效的半径")
else:
result_1 = circle_area(rad)
result_2 = circle_perimeter(rad)
print("%s半径圆的面积是:%s "%(rad,result_1))
print("%s半径圆的周长是:%s "%(rad,result_2))
def rectangular_area(long, wide):
return long * wide
def rectangular_perimeter(long, wide):
return 2 * (long + wide)
long, wide = eval(input("请分别输入矩形的长和传宽: "))
if long <= 0 and wide <= 0:
print("请输入,有效的长和宽")
else:
result_1 = rectangular_area(long, wide)
result_2 = rectangular_perimeter(long, wide)
print("{}长、{}宽的矩行面积是: {}".format(long, wide, result_1))
print("{}长、{}宽的矩行周长是: {}".format(long, wide, result_2))