Question

sides   of   a   right   triangle,   and   a   string,   which   is   either   “S”   or   “H”,   and   re

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1
def getLength(p1, p2, myString):
    if myString == "S":
        result = (max([p1, p2]) ** 2 - min([p1, p2]) ** 2) ** 0.5
    else:
        result = (p1 ** 2 + p2 ** 2) ** 0.5
    return round(result, 1)


print(getLength(3, 4, "H"))
print(getLength(3, 4, "S"))
Add a comment
Know the answer?
Add Answer to:
sides   of   a   right   triangle,   and   a   string,   which   is   either   “S”   or   “H”,   and   re
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a JavaScript function called getHypotenuse that returns the length of the hypotenuse of a right...

    Write a JavaScript function called getHypotenuse that returns the length of the hypotenuse of a right triangle given the length of the other two sides. You can utilize the Pythagorean Theorem. Test your function with the following data. getHypotenuse(3, 4) should return 5 getHypotenuse(6, 8) should return 10 Rewrite the above function as an arrow function.

  • 6. The sides of a right triangle are measured to be a = 7.80 ± 0.02...

    6. The sides of a right triangle are measured to be a = 7.80 ± 0.02 cm and b = 6.40 ± 0.02 cm. Determine the length of the hypotenuse of the triangle (given by ?^2 +?^2 = ?^2) and the uncertainty in the length. (Hint: you need to use the derivative equation to find the uncertainty.) 7. If you drive 146 miles in a time of 3.25 hours, what is your average speed in km/h and m/s? How long...

  • Write the java program: A right triangle can have sides whose lengths are all integers. The...

    Write the java program: A right triangle can have sides whose lengths are all integers. The set of three integer values for the length of the sides of a triangle is called a Pythagorean triple. The length of the three sides must satisfy the relationship that the sum of the squares of the sides is equal to the square of the hypotenuse. Write a Java application that prompts the user for an integer that represents the largest side value and...

  • Write the java program: A right triangle can have sides whose lengths are all integers. The...

    Write the java program: A right triangle can have sides whose lengths are all integers. The set of three integer values for the length of the sides of a triangle is called a Pythagorean triple. The length of the three sides must satisfy the relationship that the sum of the squares of the sides is equal to the square of the hypotenuse. Write a Java application that prompts the user for an integer that represents the largest side value and...

  • ) 8. Suppose a triangle is constructed where two sides have fixed length a and b, but the third side has variable length x You can imagine there is a pivot point where the sides of fixed length a and...

    ) 8. Suppose a triangle is constructed where two sides have fixed length a and b, but the third side has variable length x You can imagine there is a pivot point where the sides of fixed length a and b meet, forming an angle of θ. By changing the angle θ, the opposite side will either stretch or contract (a) Let K(x)- Vs(s - a)(s -b)(s - x), where s is the semiperimeter of the triangle. Accord ing to...

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • 1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the are...

    1. Write a C++ program that reads sides of a triangle a, b and c from a file and computes the area of a triangle and counts total number of areas program has computed Program should have two functions sfun(): sfun receives the values of a, b and c then computes and returns the value ofs as areafun 0: areafun receives the value of s and computes and return the area of a triangle to main program using below formulae...

  • For this i presented problem number 80 from section 10.4. i need to answer the following question...

    for this i presented problem number 80 from section 10.4. i need to answer the following questions in the third picture. just those questions. no cursive please its hard to read. Math 213-101 Section 10.4 Discussion #80-Saved to this PC Layout References Mailings Review View Help Tell me what you want to do Problem: Historical Pathways. Throughout recorded history, people in various walls of life have had a recrentional interest in nathematics. For example, Represenlative James A Garfield discovered a...

  • Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve...

    Project 1 – Classes and Top-down Design Overview Software development projects using the object-oriented approach involve breaking the problem down into multiple classes that can be tied together into a single solution. In this project, you are given the task of writing some classes that would work together for providing a solution to a problem involving some basic computations. Learning Objectives The focus of this assignment is on the following learning objectives: • Be able to identify the contents of...

  • Compute the following problems using Math Lab.   Instructions: Answer All Questions using MATLAB commands. Question 1....

    Compute the following problems using Math Lab.   Instructions: Answer All Questions using MATLAB commands. Question 1. Create a vector of the even whole numbers between 31 and 75. Question 2. Let x [2516] a. Add 16 to each element b. Add 3 to just the odd-index elcments c. Compute the square root of each element d. Compute the square of each element Question 3. Let x 13 268T and y [4 1 3 5] (NB. x and y should be...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT