WAP to input 3 sides of triangle and find area of the triangle.......plz plz photo bhej ke smjhana
Answers
def area_of_triangle(a, b, c):
# semi perimeter
sp = (a + b + c) / 2
return (sp * (sp - a) * (sp - b) * (sp - c)) ** 0.5
a, b, c = [float(n) for n in input("enter a b c: ").split()]
print(f"area of traingle is: {area_of_triangle(a, b, c):.2f}")
Answer:
Before writing the program you must understand who the program is supposed to work.
For that write algorithms first,
Step 1: You have to accept 3 inputs of side length of same unit.
Since you have to use sides to find area we're gonna use Heron's Formula.
Step 2: Use the 3 input sides to find semi perimeter and store the value in a variable
Step 3: As the next steps goes you will need to find square root of products of some numbers as per the formula and for that you need to import a math module just for the sake of keeping things simple and easy.
Step 4: Store a value of area in a variable.
Step 5: Print it on the screen.
Working according to the algorithm we have the following code:
__________________________
#Area of triangle using Heron's formula:
import math
a=int(input("Enter a side length (m): "))
b=int(input("Enter another side length (m) : "))
c=int(input("Enter last side length (m) : "))
sp= (a+b+c)/2
area=math.sqrt(sp*(sp-a)*(sp-b)*(sp-c))
print("The area will be ", area, "meter squared")
__________________________
I attached an image and a test code to verify this have a look.
You can yourself find area of a 3m, 4m and 5m (Pythagorean triangle) sided triangle with 1/2*length*breath so it'll be easier to verify.