예제 #1
0
def test_triangle():
    """
    test triangle and search count of errors
    :return: int
    """
    errors = 0
    try:
        import triangle
        import point
    except:
        errors += 1
    try:
        triangle = triangle.Triangle(point.Point(1, 1), point.Point(3, 1),\
                                     point.Point(2, 3))
    except:
        errors += 1
    try:
        print(triangle.is_triangle())
    except:
        errors += 1
    try:
        print(triangle.perimeter())
    except:
        errors += 1
    try:
        print(triangle.area())
    except:
        errors += 1
    try:
        print(triangle)
    except:
        errors += 1
    return errors
예제 #2
0
def main():
    # The choice variable controls the loop
    # and holds the user's menu choice.
    choice = 0

    while choice != QUIT_CHOICE:
        # display the menu.
        display_menu()

        # Get the user's choice.
        choice = int(input('Enter your choice: '))

        # Perform the selected action.
        if choice == AREA_CIRCLE_CHOICE:
            radius = float(input("Enter the circle's radius: "))
            print('The area is', circle.area(radius))
        elif choice == CIRCUMFERENCE_CHOICE:
            radius = float(input("Enter the circle's radius: "))
            print('The circumference is', \
                  circle.circumference(radius))
        elif choice == AREA_RECTANGLE_CHOICE:
            width = float(input("Enter the rectangle's width: "))
            length = float(input("Enter the rectangle's length: "))
            print('The area is', rectangle.area(width, length))
        elif choice == PERIMETER_RECTANGLE_CHOICE:
            width = float(input("Enter the rectangle's width: "))
            length = float(input("Enter the rectangle's length: "))
            print('The perimeter is', \
                  rectangle.perimeter(width, length))
        elif choice == AREA_TRIANGLE_CHOICE:
            base = float(input("Enter the triangle's base: "))
            height = float(input("Enter the triangle's height: "))
            print("The area is", \
                triangle.area(base, height))
        elif choice == PERIMETER_TRIANGLE_CHOICE:
            side1 = float(input("Enter the first side's length: "))
            side2 = float(input("Enter the second side's length: "))
            side3 = float(input("Enter the third side's length: "))
            print('The perimeter is', \
                triangle.perimeter(side1, side2, side3))
        elif choice == QUIT_CHOICE:
            print('Exiting the program...')
        else:
            print('Error: invalid selection.')
예제 #3
0
def main():
    print(
        'Program geometria pozwala obliczyć pole i obwód koła, prostokąta i trójkata.'
    )

    # W pętli while pobierana jest od użytkownika liczba całkowita
    # odpowiadająca wybranej czynności (od 1 do 5), a następnie
    # w bloku if-elif-else odczytywane są dane i wykonywane obliczenia.
    choice = 0  #inicjalizacja zmiennej choice
    while choice != QUIT_CHOICE:
        display_menu()  #wyświetlenie menu
        #pobranie wartości od użytkownika
        choice = int(input('Wybierz opcję: '))

        #wybór czynności
        if choice == AREA_CIRCLE_CHOICE:  #pole koła
            radius = circle.get_radius()
            print('Pole koła wynosi', circle.area(radius))
        elif choice == CIRCUMFERENCE_CHOICE:  #obwód koła
            radius = circle.get_radius()
            print('Obwód koła wynosi', circle.circumference(radius))
        elif choice == AREA_RECTANGLE_CHOICE:  #pole prosokąta
            (length, width) = rectangle.get_dimensions()
            print('Pole prostokąta wynosi', rectangle.area(length, width))
        elif choice == PERIMETER_RECTANGLE_CHOICE:  #obwód prostokąta
            (length, width) = rectangle.get_dimensions()
            print('Obwód prostokąta wynosi',
                  rectangle.perimeter(length, width))
        elif choice == AREA_TRIANGLE_CHOICE:  #pole trójkąta
            (a, b, c) = triangle.get_lengths()
            print('Pole trójkąta wynosi', triangle.area(a, b, c))
        elif choice == PERIMETER_TRIANGLE_CHOICE:  #obwód trójkąta
            (a, b, c) = triangle.get_lengths()
            print('Obwód trójkąta wynosi', triangle.perimeter(a, b, c))
        elif choice == QUIT_CHOICE:  #koniec programu
            print('Zakończenie działania programu.')
        else:  #wartość spoza listy
            print('Błąd: nieprawidłowa opcja.')
예제 #4
0
 def test2(self):
     assert triangle.area(4,3) ==6 #Test 2 Fails
예제 #5
0
 def test1(self):
     assert triangle.area(3,2) == 3 #test 1 fails
예제 #6
0
#!/usr/bin/env python3
import triangle
import rectangle
import circle

print("Equilateral Triangle, side 4:")
print("a: {0}, p: {1}".format(triangle.area(4, 4, 4),
                              triangle.perimeter(4, 4, 4)))
print("Square, side 4:")
print("a: {0}, p: {1}".format(rectangle.area(4, 4), rectangle.perimeter(4, 4)))
print("Rectange, sides 4, 5:")
print("a: {0}, p: {1}".format(rectangle.area(4, 5), rectangle.perimeter(4, 5)))
print("Circle, radius 3:")
print("a: {0}, p: {1}".format(circle.area(3), circle.perimeter(3)))
예제 #7
0
import triangle
import point

if __name__ == '__main__':
    triangle = triangle.Triangle(point.Point(1, 1), point.Point(3, 1), point.Point(2, 3))
    assert triangle.is_triangle()
    assert triangle.perimeter() == 6.47213595499958
    assert triangle.area() == 2.0
 def testArea(self):
     self.assertEqual(area(3, 4), 6)
     self.assertEqual(area(7, 4), 14)
예제 #9
0
 def test1(self):
     width = 4
     height = 12
     area = 24
     assert triangle.area(width, height) == area #Test 1 fails
예제 #10
0
 def test2(self):
     width = 6
     height = 2
     area = 6
     assert triangle.area(width, height) == area #Test 2 fails
예제 #11
0
import triangle

filein = open("triangles.txt")
fileOut = open ('answers.txt', 'wt')
for line in filein:
    height, width = line.split (',')
    area = triangle.area(float(height), float(width))
    fileOut.write("""A triangle of width {0}, and height {1}, 
    will have an area of {2}\n""".format(float(width), float(height), area))
fileOut.close()
    
#!/usr/bin/env python3
import triangle
import rectangle
import circle

print("Equilateral Triangle, side 4:")
print("a: {0}, p: {1}".format(triangle.area(4,4,4), triangle.perimeter(4,4,4)))
print("Square, side 4:")
print("a: {0}, p: {1}".format(rectangle.area(4,4), rectangle.perimeter(4,4)))
print("Rectange, sides 4, 5:")
print("a: {0}, p: {1}".format(rectangle.area(4,5), rectangle.perimeter(4,5)))
print("Circle, radius 3:")
print("a: {0}, p: {1}".format(circle.area(3), circle.perimeter(3)))
예제 #13
0
 def test2(self):
     assert triangle.area(4, 3) == 6  # test 2 fails
예제 #14
0
def main():

    # The choice variable controls the loop
    # and holds the user's menu choice.
    choice = 0

    while not (choice == 5):
        # display the menu.
        display_menu()

        # Get the user's choice.
        choice = int(input('Enter your choice: '))

        # Perform the selected action.
        if choice == 1:
            r = float(input("Enter the circle's radius: "))
            print('The area is {:.3f}.'.format(circle.area(r)))
        elif choice == 2:
            radius = float(input("Enter the circle's radius: "))
            print('The circumference is {:.3f}'.\
                    format(circle.circumference(radius)))
        elif choice == 3:
            width = float(input("Enter the rectangle's width: "))
            length = float(input("Enter the rectangle's length: "))
            print("The area is {:.3f}".format(rectangle.area(width, length)))
        elif choice == 4:
            width = float(input("Enter the rectangle's width: "))
            length = float(input("Enter the rectangle's length: "))
            print('The perimeter is {:.3f}'.\
                    format(rectangle.perimeter(width, length)))
        elif choice == 5:
            base = float(input("Enter triangle's base length: "))
            height = float(input("Enter the triangle's height: "))
            print("The area is: {:.3f}".format(triangle.area(height, base)))

        elif choice == 6:
            side_a = float(input("Enter the length of the side a: "))
            side_b = float(input("Enter the length of the side b: "))
            side_c = float(input("Enter the length of the side c: "))
            print("The perimeter of the triangle is: {:.3f}".\
                  format(triangle.perimeter(side_a, side_b, side_c)))

        elif choice == 7:
            radius = float(input("Enter the sphere's radius: "))
            print("The surface area of the sphere is: {:.3f}".\
                  format(sphere.surface(radius)))

        elif choice == 8:
            height = float(input("Enter the sphere's height: "))
            radius = float(input("Enter the sphere's radius: "))
            print("The volume of the sphere is: {:.3f}".\
                  format(sphere.volume(height,radius)))

        elif choice == 9:
            height = float(input("Enter the cylinder's height: "))
            radius = float(input("Enter the cylinder's radius: "))
            print("The surface area of the cylinder is: {:.3f}".\
                  format(cylinder.surface(height, radius)))

        elif choice == 10:
            height = float(input("Enter the cylinder's height: "))
            radius = float(input("Enter the cylinder's radius: "))
            print("The volume of the cylinder is: {:.3f}".\
                  format(cylinder.volume(height, radius)))

        elif choice == 0:
            print("Exiting the program...")
        else:
            print("Error: invalid selection.")
예제 #15
0
def test_area():
    """Unit test for the area function."""
    hypotenuse = distance(0, 100, 100, 0)
    area = triangle.area(100, 100, hypotenuse)
    assert math.isclose(5000.0, area)
예제 #16
0
def main():
    print(hypotenuse(3, 4))
    print(area(5, 10))