Q:

Write a Python Program to Calculate the Area of a Triangle

0

Write a Python Program to Calculate the Area of a Triangle.

 

example on the final output of the program:

enter the base of the triangle: 3

enter the height of the triangle: 4

the area of the triangle of base:3 and height:4 is : 6

 

 

 

hint:

Area of a Triangle = A = ½ (base × height)

Example: What is the area of a triangle with base b = 3 cm and height h = 4 cm?

Using the formula,

Area of a Triangle, A = 1/2 × b × h

= 1/2 × 4 (cm) × 3 (cm)

= 2 (cm) × 3 (cm)

= 6 cm2

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

program calculates the area of an Equilateral Triangle

Area of an Equilateral Triangle

An equilateral triangle is a triangle where all the sides are equal. The perpendicular drawn from the vertex of the triangle to the base divides the base into two equal parts. To calculate the area of the equilateral triangle, we have to know the measurement of its sides.

Area of an Equilateral Triangle = A = (√3)/4 × side2

 

Python Program:

# import the math module
import math

side=int(input("enter the side of the triangle:"))
area=math.sqrt(3)/4*(side*side)
print("the area of this equaliteral triangle is : ",area)
print("the area of this equaliteral triangle after rounding is : ",round(area,0))

need an explanation for this answer? contact us directly to get an explanation for this answer
need an explanation for this answer? contact us directly to get an explanation for this answer

base=int(input("enter the base of the triangle:"))
height=int(input("enter the height of the triangle:"))
area=(base*height)*0.5
print("the area of the triangle of base:",base," and height:",height," is : ",area)

need an explanation for this answer? contact us directly to get an explanation for this answer
need an explanation for this answer? contact us directly to get an explanation for this answer

side1 = int(input('enter side1:'))
side2 = int(input('enter side2:'))
side3 = int(input('enter side3:'))
s = (side1 + side2 + side3) / 2;
area = (s * (s - side1) * (s - side2) * (s - side3))**0.5
print("The area of the triangle is " , area);

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (3)

Similar questions


need a help?


find thousands of online teachers now