74,322 views
39 votes
39 votes
The area of a right triangle is ½ the base times the height.

Input the base and height for two triangles. You can call
them Triangle A and Triangle B. Print the area for both
triangles. Print a message saying which triangle is large or
if they are equal area. You may use the nested ifs or the if
else and elif.


Help me with the codes

User Sunshinejr
by
3.0k points

1 Answer

18 votes
18 votes

# We will use the array to store our triangles' cred.

triangles = [0,0,0,0]

#Get input from user.

triangles[0] = int(input("For Triangle A, enter the base: "))

triangles[1] = int(input("For Triangle A, enter the height: "))

triangles[2] = int(input("For Triangle A, enter the base: "))

triangles[3] = int(input("For Triangle B, enter the height: "))

#Print the areas.

print("Area of the Triangle A is: ",(triangles[0]*0.5*triangles[1]),"\\Area of the Triangle B is: ",(triangles[2]*0.5*triangles[3]))

#Find the largest or are these equal?

message = "These have the same area." if ((triangles[0]*0.5*triangles[1])==(triangles[2]*0.5*triangles[3])) else "Triangle B is larger than Triangle A." if ((triangles[0]*0.5*triangles[1]) < (triangles[2]*0.5*triangles[3])) else "Triangle A is larger than Triangle B."

print(message)

The area of a right triangle is ½ the base times the height. Input the base and height-example-1
User Jolle
by
3.2k points