Computer Science, asked by toilibb, 10 months ago

write a function called tri area that returns the area of a triangle with base b and height h , where b and h are input argument of the function in that order

Answers

Answered by poojan
1

Program with a function called tri area that returns the area of a triangle with base b and height h, where b and h are input argument of the function in that order

Language using : Python Programming.

Area of triangle :  \frac{1}{2} * base * height

Program :

def tri_area(b,h):

  return( (1/2)*b*h )    

  # Or you can simply place this computation in avariable and return it.

#As the base and height can't always be an integer, let us take float values.

b=float(input("Enter the base of the triangle : "))

h=float(input("Enter the height of the triangle : "))

print("Area of the triangle is : ", tri_area(b,h), " Square units.")

Input 1 :

Enter the base of the triangle : 20

Enter the height of the triangle : 30

Output 1 :

Area of the triangle is :  300.0  Square units.

Input 2 :

Enter the base of the triangle : 91.64

Enter the height of the triangle : 72.83

Output 2 :

Area of the triangle is :  3337.0706  Square units.

Explanation :

  • First take two values (base, height) into two variables from user as an input.

  • Write a function using def keyword. The function need to send the area by calculating based on the base and height parameters sent during the function call.

  • You can directly make the computation happen in written statement, or you can compute it in the function ad store the resultant value into a variable, return that variable that has the value.

  • Make a function call with the needed parameters so that the function performs action and sends you the result.

Learn more :

1. Program to perform Arithmetic operations using function.

brainly.in/question/18905944

2. Write a simple python function to increase the value of any number by a constant "C=5"

brainly.in/question/16322662

Attachments:
Similar questions