Program that accepts the lengths of three sides of a triangle as inputs.

    Write the following two programs using Python Language. Q1. Write a program that accepts the lengths of three sides of a triangle as inputs. The program output should indicate whether or not the triangle is an equilateral triangle.
Python
def is_equilateral(side1, side2, side3):
    """Determines if a triangle is equilateral based on its side lengths."""

    return side1 == side2 == side3

# Get the lengths of the triangle's sides from the user
side1 = float(input("Enter the length of side 1: "))
side2 = float(input("Enter the length of side 2: "))
side3 = float(input("Enter the length of side 3: "))

# Check if the triangle is equilateral
if is_equilateral(side1, side2, side3):
    print("The triangle is equilateral.")
else:
    print("The triangle is not equilateral.")

Explanation:

  1. is_equilateral function:

    • Takes three side lengths as input.
    • Returns True if all three sides are equal, indicating an equilateral triangle.
    • Returns False otherwise.
  2. Input:

    • Prompts the user to enter the lengths of the three sides using input().
    • Converts the inputs to floating-point numbers using float().
  3. Check for equilateral triangle:

    • Uses the if statement to check the result of the is_equilateral function.
    • Prints the appropriate message based on the result.

Sample Solution

Comply today with Compliantpapers.com, at affordable rates

Order Now