Write a python program that calculates the area of triangle. The user will be asked to enter the base (b) and the height (h). The formula to calculate the area is:
Triangle_area=(bh)/2
Note: the program should print the area to the user: (for example: the area of the triangle is: 34.3)
As per question, we need to take two input from user. First is height of the triangle and second is base. For that we need to create two variables.
Then we need to cast the user input value into float. So, that program will throw an error when user try to enter string value.
After that we need to create a area variable which will store the result of formula for calculating the area.
Now, we need to print the result. So, inside the print function we need to use format mathod to show the result as per requirement.
var_height = float(input("Enter the height of triangle:
"))
var_base = float(input("Enter the base of triangle: "))
var_area = var_height*var_base*0.5
print("The area of triangle is: {}".format(var_area))
Get Answers For Free
Most questions answered within 1 hours.