Last active
March 16, 2024 05:59
-
-
Save amirsinaa/b308bcf852483196dee9bbebe7803829 to your computer and use it in GitHub Desktop.
Python code that receives the sides of a quadrilateral and tells its type
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def is_square(sides, angles): | |
return all(side == sides[0] for side in sides) and all(angle == 90 for angle in angles) | |
def is_rectangle(angles): | |
return all(angle == 90 for angle in angles) | |
def is_rhombus(sides): | |
return all(side == sides[0] for side in sides) | |
def is_parallelogram(angles): | |
return angles[0] == angles[2] and angles[1] == angles[3] | |
def is_kite(sides): | |
return sides.count(sides[0]) == 2 and sides.count(sides[1]) == 2 | |
def is_trapezoid(angles): | |
return angles[0] == 90 or angles[1] == 90 or angles[2] == 90 or angles[3] == 90 | |
def determine_quadrilateral_type(sides, angles): | |
if is_square(sides, angles): | |
return "square" | |
elif is_rhombus(sides) and is_rectangle(angles): | |
return "diamond" | |
elif is_rectangle(angles): | |
return "rectangle" | |
elif is_parallelogram(angles): | |
if is_rhombus(sides): | |
return "rhombus" | |
elif is_kite(sides): | |
return "kite" | |
else: | |
return "parallelogram" | |
elif is_kite(sides): | |
return "kite" | |
elif is_trapezoid(angles): | |
if angles[0] == 90 or angles[1] == 90: | |
return "right trapezoid" | |
else: | |
return "isosceles trapezoid" | |
else: | |
return "trapezium" | |
sides = [] | |
angles = [] | |
print("Enter the length of side AB:", end=" ") | |
sides.append(int(input())) | |
print("Enter the length of side BC:", end=" ") | |
sides.append(int(input())) | |
print("Enter the length of side CD:", end=" ") | |
sides.append(int(input())) | |
print("Enter the length of side DA:", end=" ") | |
sides.append(int(input())) | |
print("Enter the size of angle A:", end=" ") | |
angles.append(float(input())) | |
print("Enter the size of angle B:", end=" ") | |
angles.append(float(input())) | |
print("Enter the size of angle C:", end=" ") | |
angles.append(float(input())) | |
print("Enter the size of angle D:", end=" ") | |
angles.append(float(input())) | |
quadrilateral_type = determine_quadrilateral_type(sides, angles) | |
print(f"is a \"{quadrilateral_type}\"") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment