Python 三角形类,实现数据的输入、输出、周长、面积的计算
练习题
2018.10.25
import math
class Triangle:
def __init__(self):
a=0
b=0
c=0
def add(self):
self.a=int(input("输入第1条边的长度:"))
self.b=int(input("输入第2条边的长度:"))
self.c=int(input("输入第3条边的长度:"))
while (self.a+self.b<=self.c):
print("不符合三角边的规定,重新输入!")
self.a=int(input("输入第1条边的长度:"))
self.b=int(input("输入第2条边的长度:"))
self.c=int(input("输入第3条边的长度:"))
def out(self):
print (self.a,self.b,self.c)
def length(self):
print (self.a+self.b+self.c)
def area(self):
print ((((a+b+c)/2)-a)*(((a+b+c)/2)-b)*(((a+b+c)/2)-c)*((a+b+c)/2))
t=Triangle()
t.add()
t.out()
t.length()
t.area()