Write a Python Program to Calculate the Area of a Triangle

In this tutorial, we will be discussing how to calculate the area of a triangle using Python programming language.

We will be using a simple formula that involves the base and height of the triangle.

Formula: Area of a triangle = (base * height) / 2

Now let’s dive into the Python code to calculate the area of a triangle.

# Get the base and height of the triangle as user input
base = float(input("Enter the base of the triangle: "))
height = float(input("Enter the height of the triangle: "))

# Calculate the area of the triangle
area = (base * height) / 2

# Print the result
print("The area of the triangle is:", area)

In the code above, we first get the base and height of the triangle as user input using the input() function.

The float() function is used to convert the user input from a string to a floating-point number.

Next, we use the formula area = (base * height) / 2 to calculate the area of the triangle.

Finally, we print the result using the print() function.

The output will display the calculated area of the triangle.

This is a simple program to calculate the area of a triangle using Python.

We hope this tutorial was helpful to you.