Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

PYTHON Create in your source_files directory, create a python file inner_functions_assignment.py. In your test directory, create a unit test file test_inner_functions.py. In your inner_functions_assignment.py, write

PYTHON

Create in your source_files directory, create a python file inner_functions_assignment.py. In your test directory, create a unit test file test_inner_functions.py.

In your inner_functions_assignment.py, write a function measurements that accepts a list of measurements for a rectangle and returns a string with perimeter and area

  • Write 2 inner functions that accept a list as parameter
    • area(a_list) -- calculates the area
      • recall accessing items in a list: a_list[index_position]
    • perimeter(a_list) -- calculates the perimeter
      • recall accessing items in a list: a_list[index_position]
  • The outer function, measurements function will call the area() and the perimeter() inner functions
  • The outer function will build a string and return the following string:
    • Perimeter = 11.0 Area = 7.14 # if this is the perimeter and the area.
  • Test your code with the unit test below, and notice only the first test will pass.
class MyTestCase(unittest.TestCase): def test_measurements_rectangle(self): self.assertEqual(measurements([2.1, 3.4]), "Perimeter = 11.0 Area = 7.14") def test_measurements_square(self): self.assertEqual(measurements([3.5]), "Perimeter = 14.0 Area = 12.25") if __name__ == '__main__': unittest.main()

  • Add necessary statements to allow your function to calculate for a square in perimeter and in area.
    • len(a_list) is helpful to decide if the list has 1 or 2 items.

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

Modern Datalog Engines In Databases

Authors: Bas Ketsman ,Paraschos Koutris

1st Edition

1638280428, 978-1638280422

More Books

Students also viewed these Databases questions