# -------------------------------------------------------------- # Length of vector # -------------------------------------------------------------- def length(vector) : '''Assumes that vector is a tuple of floating point values. Returns the square root of the sum of the squares of the elements of vector. Hint: math.sqrt(25) is 5.0 For example, length((1, 1)) returns a value close to 1.414, since sqrt(1**2 + 1**2) = sqrt(2) = 1.414 length((-1.0, 2.0, 2.0, -1.0)) returns 3.1623, i.e., sqrt(1 + 4 + 4 + 1) = sqrt(10) ''' pass # -------------------------------------------------------------- # The Testing # -------------------------------------------------------------- class myTests(unittest.TestCase): def test1(self): self.assertAlmostEqual(length((1, 1)), 1.4142136, delta=0.0001) def test2(self): self.assertAlmostEqual(length((-1, 2, 2, -1)), 3.16228, delta=0.0001) def test3(self): self.assertAlmostEqual(length((0.5, 9.3, 0.8)), 9.34773, delta=0.0001) def test4(self): self.assertAlmostEqual(length((0,)), 0, delta=0.0001) def test5(self): self.assertAlmostEqual(length((50.2, 50.3)), 71.0643, delta=0.0001) if __name__ == '__main__': unittest.main(exit=True)

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

# --------------------------------------------------------------
# Length of vector
# --------------------------------------------------------------
def length(vector) :
'''Assumes that vector is a tuple of floating point values.
Returns the square root of the sum of the squares of the elements of vector.
Hint: math.sqrt(25) is 5.0

For example, length((1, 1)) returns a value close to 1.414,
since sqrt(1**2 + 1**2) = sqrt(2) = 1.414
length((-1.0, 2.0, 2.0, -1.0)) returns 3.1623, i.e., sqrt(1 + 4 + 4 + 1) = sqrt(10)
'''
pass
# --------------------------------------------------------------
# The Testing
# --------------------------------------------------------------
class myTests(unittest.TestCase):
def test1(self):
self.assertAlmostEqual(length((1, 1)), 1.4142136, delta=0.0001)
def test2(self):
self.assertAlmostEqual(length((-1, 2, 2, -1)), 3.16228, delta=0.0001)
def test3(self):
self.assertAlmostEqual(length((0.5, 9.3, 0.8)), 9.34773, delta=0.0001)
def test4(self):
self.assertAlmostEqual(length((0,)), 0, delta=0.0001)
def test5(self):
self.assertAlmostEqual(length((50.2, 50.3)), 71.0643, delta=0.0001)

if __name__ == '__main__':
unittest.main(exit=True)

Expert Solution
Step 1

Hi.

 

Let's move on to the code in the next step.

I have included comments in the code that will help you in understanding the code better.

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY