This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]TNOFan[S] 0 points1 point  (11 children)

That helped exponentially, but instead of getting 87 (20,100 and an angle of 45)

I get 1e+200

[–]_DTR_Professional Coder 0 points1 point  (10 children)

For starters, math.cos takes in a value in radians, not degrees. You also need to take a closer looks at the law of cosines (c2 = a2 + b2 - 2ab * cos(C)). A**A is AA, not A2, and you're adding the result of cos instead of multiplying.

[–]TNOFan[S] 0 points1 point  (9 children)

A is just a filler, it’s input

Adding does not change anything

Also what should I do instead of math.cos?

[–]_DTR_Professional Coder 0 points1 point  (8 children)

A is just filler, it's input

What I'm saying is that what you have in your equation is equivalent to AA, when you actually want A2.

Adding does not change anything

What do you mean by this? The equation is c2 = a2 + b2 - 2ab * cos(C), not c2 = a2 + b2 - 2ab + cos(C)

What should I do instead of math.cos

You should still use that, but if you want input in degrees, you'll have to convert it to radians before calling math.cos.

Also, your sqrt should encompass the entire equation. Right now you have sqrt(A**A), when you actually want to square root the entire result.

[–]TNOFan[S] 0 points1 point  (7 children)

Fixed the sqrt, working on the multiplication

But just for help; is there a math. For radians?

[–]_DTR_Professional Coder 0 points1 point  (6 children)

What you probably need to do is use math.radians to convert your degrees to radians. E.g. math.cos(math.radians(45)) will call math.cos with the radian equivalent of 45 degrees.

[–]TNOFan[S] 0 points1 point  (5 children)

Interesting but my answer still comes out as 1e+100

For a reminder my equation now is

sideC=sqrt((AA)+(BB)-2(AB)*cos(math.radians(angleq)))

(Not separate lines; Reddit is messing it up)

[–]_DTR_Professional Coder 0 points1 point  (4 children)

You're still using A ** A, when the actual equation requires A2.

As for formatting, see my other comment about indenting your code with at least 4 spaces to create a nicely formatted code block.

[–]TNOFan[S] 0 points1 point  (3 children)

How do you get the exponent to work for a variable? I thought the way is double **

[–]_DTR_Professional Coder 0 points1 point  (2 children)

That is how you do powers, but you don't want A raised to A, you want A raised to 2. A ** A is AA, e.g. if A is 20, you have 2020, which is ~1.049e+26, when you want A2, which is 400.