Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!