Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. 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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Server T-SQL Recipes

Authors: David Dye, Jason Brimhall

4th Edition

1484200616, 9781484200612

More Books

Students also viewed these Databases questions

Question

Explain how options can be used to protect a short position.

Answered: 1 week ago

Question

1. Who will you assemble on the team?

Answered: 1 week ago

Question

4. Who would lead the group?

Answered: 1 week ago