Computer Science
Write a module called calculate_area() that takes base and height as an input argument and returns an area of a triangle as output. The formula used is
Triangle Area = 1⁄2 * base * height
Answer
# calculate_area.py
def area(base, height):
area = (1/2) * base * height
return area
# triangle.py
from calculate_area import area
base_value = int(input("Enter the base value: "))
height_value = int(input("Enter the height value: "))
triangle_area = calculate_area(base_value, height_value)
print("Area of the triangle:", triangle_area)
Output
Enter the base value: 10
Enter the height value: 20
Area of the triangle: 100.0
Related Questions
How does Python resolve the scope of a name or identifier?
A program having multiple functions is considered better designed than a program without any functions. Why ?
Rewrite the following Python code after removing all syntax error(s). Underline the corrections done.
def main(): r = input('enter any radius:') a = pi * maths.pow(r, 2) Print("Area = "+a) Main()How is math.ceil(89.7) different from math.floor(89.7)?