예제 #1
0
# Author          : John Kenneth Seva Lesaba
# Course and Year : BS Computer Science - 2nd year
# Filename        : lesaba_e4.py
# Description     : driver file for Graded Exercise #4
# Honor Code      : I have not given nor received any unathorized help in
#                   completing this exercise. I am also well aware of the
#                   policies stipulated in the AdNU student handbook.
import geometry as g
(a, b, c) = input("Enter the side lengths of a triangle: ").split(sep=",")
if (g.check_lenghts(float(a), float(b), float(c))):
    print("Perimeter: {:.2f}".format(g.perimeter(float(a), float(b),
                                                 float(c))))
    print("Area: {:.2f}".format(
        g.triangle_heronsarea(float(a), float(b), float(c))))
else:
    print("Error: Invalid input")
예제 #2
0
import geometry

line = input("Enter")

(a,b,c)= (float(x) for x in line.split(","))

P = geometry.triangle_perimeter(a,b,c)
A = geometry.triangle_heronsarea(a,b,c)

print ("Perimeter")
예제 #3
0
#                   in the `geometry` module and display these results. Otherwise,
#                   your program must issue an error.
# Honor Code      : I have not given nor received any unathorized help in
#                   completing this exercise. I am also well aware of the
#                   policies stipulated in the AdNU student handbook.

import geometry
import math

print("Enter the side lengths of a triangle: ",
      end=" ")  #Prompt the user to enter the side lengths of a triangle
a, b, c = map(
    float,
    input().split(",")
)  #declare the varibles as float and read it  and separate it by a comma using the funtion split()
side_lengths = a, b, c  #assigned the values to a temporary variable side_lengths

if geometry.check_If_Valid(
        a, b, c
):  #returns the perimeter and area of a triangle if the side lengths is valid
    print(
        "Perimeter: ", round(geometry.perimeter(*side_lengths), 2)
    )  #display the perimeter by calling the function created in the module and round it off to two decimals
    print(
        "Area: ", round(geometry.triangle_heronsarea(a, b, c), 2)
    )  #display the area of triangle by calling the function created in the module and round it off to two decimals
else:
    print(
        "Invalid input"
    )  # if the sum of the two side is less than the other sides it display "Invalid input"
예제 #4
0
#                   completing this exercise. I am also well aware of the
#                   policies stipulated in the AdNU student handbook.

from geometry import perimeter, triangle_heronsarea


def CheckingSides(a, b, c):
    if ((a + b) <= c) or ((b + c) <= a) or ((a + c) <= b):
        return False  # function that returns True if the sides are valid, otherwise False
    else:
        return True


a, b, c = input("Enter the sides of the triangle: "
                )  # user inputs the values of the side of the triangles
a = float(a)
b = float(b)  # a, b, and c are of type float
c = float(c)

if CheckingSides(a, b, c):
    P = perimeter(
        a, b, c)  # the perimeter and area are stored in the variables P and A
    A = triangle_heronsarea(a, b, c)  # for the function
    print("Perimeter: " +
          format(P, '.2f'))  # prints the perimeter in 2 decimal places
    print("Area: " + format(A, '.2f'))  # prints the area in 2 decimal places
else:
    print(
        "Error: Invalid input"
    )  # if the lengths are invalid, program prints "Error: Invalid input"
예제 #5
0
import geometry

data = input("Enter the side lengths of a triangle: ")
splitted_data = data.split(",")
perimeter = geometry.triangle_perimeter(float(splitted_data[0]),
                                        float(splitted_data[1]),
                                        float(splitted_data[2]))
area = geometry.triangle_heronsarea(float(splitted_data[0]),
                                    float(splitted_data[1]),
                                    float(splitted_data[2]))
print("Perimeter: %.2f" % perimeter)
print("Area: %.2f" % area)