Question
Python: Write a function that takes, as arguments, 2 values representing the lengths of 2 sides of a right triangle, and a string, which is
Python:
-
Write a function that takes, as arguments, 2 values representing the lengths of 2 sides of a right triangle, and a string, which is either S or H, and returns the length of the third side of the triangle. S indicates that the third length (i.e. the value to be computed) is the length of a leg, and H indicates that the third length (i.e. the value to be computed) is the length of the hypotenuse. Name your function getLength(p1, p2, myString). The result should be rounded to the nearest tenth. For example,
>>>getLength(3, 4, H)
should return 5.0, and
>>>getLength(3, 4, S)
should return 2.6. You may want to review the Pythagorean Theorem to get the formula needed: if right triangle has legs of length a and b, and hypotenuse of length
c, then a, b, and c satisfy the following relationship: a2 + b2 = c2 . As part of this
process, youll probably want to take the square root of some value, and make sure that you are taking the square root of a non-negative number.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started