-2

For some reason the answer I get in the program is 7.091341682475861 It is supposed to be 6.66634. Can someone please explain to me what I am doing wrong. The equation is fairly simple and straightforward?

import math as mt
 def third_side(a, b, c):
                return mt.sqrt((a * a) +
                       (b * b) - 2 * a * b * mt.cos(c))
            c = 37
            a, b = 8, 11
            print(third_side(a,b,c))
user3316598
  • 163
  • 1
  • 7
  • 2
    This code has several `IndentationError`s. Please [edit] your question and fix those errors. We can't be expected to guess which errors are significant and which are typos. The easiest way to add code is to copy it, paste it into your question, then select it and click the `{}` button or press Ctrl+K to format it as a code block. This should maintain all indentation. – ChrisGPT was on strike Jan 25 '22 at 23:10
  • 1
    What are `a`, `b`, and `c` here? Are they side lengths? Then why are there three if you're supposed to compute the third side? Are they points? Then why are they single values and not pairs or triples? Is one of them an angle? What is `third_side()` supposed to do? Please read [ask]. – ChrisGPT was on strike Jan 25 '22 at 23:12
  • Thank You Chris, I have read How to Ask and will implement it next time. – user3316598 Feb 02 '22 at 18:43

1 Answers1

2

According to https://docs.python.org/3/library/math.html#math.cos

math.cos takes input in radians. You should do mt.cos(c/180*mt.pi)

import math as mt
def third_side(a, b, c):
    return mt.sqrt((a * a) + (b * b) - 2 * a * b * mt.cos(c/180*mt.pi))
c = 37
a, b = 8, 11
print(third_side(a,b,c))
Z Li
  • 4,133
  • 1
  • 4
  • 19