QuestionQuestion

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[#]
perimeter(a_list) -- calculates the perimeter
-Recall accessing items in a list: a_list[#]

-The outer, measurements function will call the area() and the perimeter()
-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()

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

def area(a_list):
    if len(a_list) == 1:
       side_a = a_list[0]
       res = round(side_a * side_a, 2)
       return side_a * side_a
    if len(a_list) == 2:
       side_a = a_list[0]
       side_b = a_list[1]
       res = round(side_a * side_b, 2)
    return res...

By purchasing this solution you'll be able to access the following files:
Solution.py and SolutionTest.py.

$10.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats