Esempio n. 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
Esempio n. 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.')
Esempio n. 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.')
Esempio n. 4
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)))
Esempio n. 5
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 testPerimiter(self):
     self.assertEqual(perimeter(3, 4, 5), 12)
     self.assertEqual(perimeter(10.5, 6, 9.3), 25.8)
#!/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)))
Esempio n. 8
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.")