Exercise 43

Write a simple Python program that prompts the user to input the height and base of a given triangle and returns the area of the triangle.

Solution

To calculate the area of the triangle, we will use the formula: area = 0.5 * base * height

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

# Calculate the area of the triangle
area = 0.5 * base * height

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





When you run this program and enter the values for height and base, it will calculate the area of the triangle and display the result in the console. Note that we're using the float() function to convert the user input from strings to float numbers, which allows us to perform mathematical operations on them.

 

Younes Derfoufi
CRMEF OUJDA

One thought on “Solution Exercise 43: python program to calculates the area of given triangle”

Leave a Reply