|
python编程练习:求梯形的面积浏览数:225次
求梯形的面积:输入上底和下底和高,输出面积。面积要求保留两位有效数字, def calc(): top = int(input("输入梯形的上底:")) bottom = int(input("输入梯形的下底:")) heigh = int(input("输入梯形的高:")) area = ((top + bottom)*heigh)/2 print("该梯形的面积为:%0.2f"%(area)) while 1: try: calc() break except: print("输入错误,请重新输入!")
|