#Confusion on Isosceles Triangle Function

106 messages · Page 1 of 1 (latest)

frail ember
#

I have a code to calculate the isosceles triangle area. The leg length is 5 and the height is 4 to test my code. However, in the example that also uses the same value the answer is 12 but I keep getting 10. I'm unsure of what's wrong with the calculation. I'm guessing the leg length and height are different from the side length not sure how to word it. Help would be appreciated thank you for your time!

Here is my code for the calculation:

naive falcon
frail ember
#

I'm not sure what they did differently

mild sky
#

Maybe the leg length is not the length of the base of the triangle? Because your calc is correct area of triangle is half * base * height

frail ember
mild sky
#

What does the code output

frail ember
#

My code

#

Vs this example

mild sky
#

Hm

#

Whats the code used for thr example

frail ember
#

There is no code in the example 😭

#

It just shows what the output should be

mild sky
#

Unless I'm forgetting what the area of a triangle is haha the example seems wrong

#

Hol up

#

Yeah 1/2L.H

#

Is there more context provided to the example?

frail ember
#

Here is this context I got not sure what they mean though

mild sky
#

Hm I'm also not sure how they differentiate between a leg and base hold on

#

one can calculate the length of the legs of an isoceles triangle by dividing the length of the hypotenuse by the square root of 2.

#

So leg length is not the base of the triangle

#

Legs: The two equal sides of an isosceles triangle are known as 'legs'.

frail ember
#

So then legs are not the base

#

The two sides equal to the hypotenuse are the legs?

mild sky
#

Yeah makes mlre sense now you can just use Pythagoras to find base

mild sky
#

So base length would be √5^2 - 4^2

#

= 3 which is half the base length

#

So area is 1/2 * 6 * 4 = 12

#

So in this problem you need to convert leg length to base length

frail ember
#

So 1/2 * b x h for conversion to the base length? (Area formula note for myself)

mild sky
#

That's the formula for area yeah

#

But to convert leg length to base length you would use Pythagoras

frail ember
#

Oh the Pythagorean theorem

#

Right?

mild sky
mild sky
#

Just solve for x here and you sould get base length

frail ember
#

Hmm but it has to be user input

#

Brainstorming ways to transfer this to code

mild sky
#

You can user input any value and compute that value later on as you like

#

It's late for me but if you are still stuck in maybe 6-7 hours i could help you then

#

Or someone else

frail ember
#

Alrighty I'm gonna test this out for a bit then

frail ember
#

Welp I still get 10

naive falcon
#

do you understand how toady got the answer?

frail ember
#

Yes by using the Pythagorean theorem and then using it to find the area

naive falcon
#

how are you still getting 10?

frail ember
#

I have no clue I'm gonna have to adjust the code more

#

Its not working at the moment

naive falcon
frail ember
#

All of this

naive falcon
frail ember
naive falcon
#

yes

frail ember
#

So then need to take square root of the variables?

#

Leg length and height

naive falcon
#

of the whole thing

frail ember
#

(leg_length - height_2) * 0.5

naive falcon
#

no

#

square the variables, subtract them and then square root it

frail ember
#

I'm so sorry 😦

naive falcon
#

it's alright. don't worry

frail ember
#

Wait I typed it wrong

#

I'm like multitasking sorry

#

(leg_length2 - height_22)*0.5

#

discord bolded it but like in code its **2

naive falcon
#

to square root it, you would use ** 0.5

frail ember
#

Oh so for exponents and square root its **

#

Okayy

#

So then (leg_length ** 2 - height ** 2) ** 0.5

naive falcon
#

yeah

frail ember
#

Okay so got the theorem

naive falcon
#

you get 3 when you print theorem?

frail ember
#

Yes

naive falcon
#

good

#

now you just need to plug it in the area formula

frail ember
#

Which is 1/2 * leg length * height_2

#

But like thinking of where to plug in theorem

naive falcon
#

the formula uses base, not the length

#

what you got from the theorem is half of the base

frail ember
#

Leg length is prompting the user so that's why I said leg length

naive falcon
#

The purpose of leg length is to calculate the base

frail ember
#

Ahh okay

#

Ohh wait so its 1/2 * theorem * height_2

frail ember
naive falcon
#

that will be the same as what you have right now

frail ember
#

Same as what I have?

naive falcon
#

It is also 3

frail ember
#

Oh wait yeah

#

area = theorem * height_2

naive falcon
#

yeah, that works

frail ember
#

Oh damn

#

I just understood it

#

Let me try other values just in case

#

Okayy I think it works good enough

naive falcon
frail ember
#

But how else would you have done it?

naive falcon
#

I would have done it like that

frail ember
#

Ah got it

#

Thank you so much 😄

frail ember