Python Program - Calculate the Area of a Triangle
https://www.theitroad.com
Here's a Python program to calculate the area of a triangle:
# take input from the user
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 = 0.5 * base * height
# display the area of the triangle
print("The area of the triangle is:", area)
Output:
Enter the base of the triangle: 8 Enter the height of the triangle: 5 The area of the triangle is: 20.0
In this program, we take the base and height of the triangle as input from the user using the input() function. We convert these inputs to floating-point numbers using the float() function.
We then calculate the area of the triangle using the formula 0.5 * base * height and store the result in a variable called area.
Finally, we display the area of the triangle using the print() function.
