def get_rand_area(c):
    p1 = c.random_point_on_circumference()
    p2 = c.random_point_inside()
    p3 = c.random_point_inside()
    t = Triangle(p1, p2, p3)
    print('{0} with area {1:.2f}'.format(t, t.area()))
    return t.area()
Exemplo n.º 2
0
    def test_triangle_negative_area_negative_mantissa(self):
        """Negative test of Triangle.area method. Give -1 as mantissa value."""
        t = Triangle(Point(0, 3.1415), Point(2.7, 3), Point(3**0.5, 6.023))

        with self.assertRaises(ValueError) as err:
            t.area(-1)
            self.assertEqual(
                err.args[0], "Negative number for mantissa is not allowed.",
                "Triangle(Point(0, 3.1415), Point(2.7, 3), Point(3 ** 0.5, 6.023)).area(-1) failed,\
                              no ValueError was raised.")
Exemplo n.º 3
0
 def test_triangle_positive_area(self):
     """Positive test of Triangle.area method."""
     t = Triangle(Point(0, 3.1415), Point(2.7, 3), Point(3**0.5, 6.023))
     self.assertEqual(
         t.area(1), 4.0,
         "Test of Triangle(Point(0, 3.1415), Point(2.7, 3), Point(3 ** 0.5, 6.023)).area(1),\
                       returned value != 4.0.")
     self.assertEqual(
         t.area(), 4.013,
         "Test of Triangle(Point(0, 3.1415), Point(2.7, 3), Point(3 ** 0.5, 6.023)).area(1) failed,\
                       returned value != 4.013.")
     self.assertEqual(
         t.area(6), 4.012568,
         "Test of Triangle(Point(0, 3.1415), Point(2.7, 3), Point(3 ** 0.5, 6.023)).area(6) failed,\
                       returned value != 4.012568.")
Exemplo n.º 4
0
def triangle():
	if request.method == "GET":
		return jsonify({"area":"undefined"})
	elif request.method == "POST":
		amazing = request.json["amazing"]
		height = request.json["height"]
		this_triangle = Triangle(amazing, height)
		area = this_triangle.area()
		return jsonify({"triangle_area":area})
Exemplo n.º 5
0
def main():
    rect = Rectangle()
    sq = square(6)
    tri = Triangle()
    rect.breadth = 5
    rect.length = 30

    sq.length = 6
    tri = Triangle()
    result1 = rect.area()
    result2 = tri.area()
    result3 = sq.area()
    #always observe the object used
    final = result3 + result2 + result1
    print("behold... the reuslt", final)
Exemplo n.º 6
0
def main():
    """Start of program for shapes and inheritance"""

    print("\nShapes and inheritance practice in Python (v3.3.5)")

    circ = Circle(3)
    tri = Triangle(4, 5, 7, 5.7)
    sq = Square(11)

    #To print out pydocs: print(help(circ))
    print("Circle area: " + str(circ.area()))
    print("Square area: " + str(sq.area()))
    print("Triangle area: " + str(tri.area()))
    print("Circle perimeter: " + str(circ.perimeter()))
    print("Square perimeter: " + str(sq.perimeter()))
    print("Triangle perimeter: " + str(tri.perimeter()))
Exemplo n.º 7
0
def params():
	amazing = request.args.get('amazing',10)
	height = request.args.get('height',10)
	this_triangle = Triangle(int(amazing), int(height))
	area = this_triangle.area()
	return jsonify({"triangle_area":area})
Exemplo n.º 8
0
from Rectangle import Rectangle
from Triangle import Triangle
rect = Rectangle()
tri = Triangle()
rect.set_values(50, 40)
tri.set_values(50, 40)

rect.set_color('red')
tri.set_color('blue')

print(rect.area())
print(tri.area())

print(rect.get_color())
print(tri.get_color())
Exemplo n.º 9
0
from Figure import Figure
from Triangle import Triangle
from Cuadrado import Cuadrado
from Circle import Circle
import math

if __name__ == '__main__':
    fig=Figure("Cuadro")
    fig.setName("Cuadros")
    print(fig.getName())

    triangulo=Triangle("triangulo",25)
    print(triangulo.getSide())
    triangulo.perimeter()
    triangulo.area()

    cuadro=Cuadrado("cuadro",30)
    cuadro.setSide(25)
    cuadro.perimeter()
    cuadro.area()

    circulo=Circle("circulo",25)
    circulo.perimeter()
    circulo.area()
Exemplo n.º 10
0
from Triangle import Triangle
from Rectangle import Rectangle

Green_triangle = Triangle("GREEN", 2, 2)
Triangle_area = Green_triangle.area()

print(int(Triangle_area))

Green_rectangle = Rectangle("GREEN RECTANGLE", 2, 2)
Rectangle_area = Green_rectangle.area()

print(int(Rectangle_area))
Exemplo n.º 11
0
    list = []
    while n < numOfSide:
        try:
            list.append(float(input("Enter the side length: ")))
            n += 1
        except:
            print("Please enter number only!")
    return list


if __name__ == "__main__":
    side = int(input("Please enter the number of sides: "))
    if side == 3:
        print("This is a Triangle.\n")
        Tri1 = Triangle(loopTriangle(side))
        print("The area for triangle is {0:.2f}".format(Tri1.area()))
    elif side == 4:
        shape1 = loopRectangle(side/2)
        temp = shape1[0]
        if temp == shape1[1]:
            print("This is a Square.\n")
            Squ1 = Square(shape1)
            print("The area for square is {0:.2f}".format(Squ1.area()))

        elif temp != shape1[1]:
            print("This is a Rectangle.\n")
            Rec1 = Rectangle(shape1)
            print("The area for rectangle is {0:.2f}".format(Rec1.area()))

    else:
        print("error.")