Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 1 Create a function named feet_to_inches(ft) 1.1 Add assert to check 'ft' is an int with error message = 'feet is not an integer'

Question 1

  1. Create a function namedfeet_to_inches(ft)
  2. 1.1 Add assert to check 'ft' is anintwith error message = 'feet is not an integer'
  3. 1.2 Convert 'ft' to 'inches'
  4. 1.3 Return the value of 'inches'
  5. Call feet_to_inches(ft) with ft = 10
  6. Call feet_to_inches(ft) with ft = 5
  7. Call feet_to_inches(ft) with ft = 0
  8. Call feet_to_inches(ft) with ft = 'ten'

In [ ]:

def feet_to_inches(ft)

Question 2

  1. Use the function namedavg_grades(grades)provided
  2. 1.1 Add assert to check 'grade' isgreater than or equal to 0with error message = 'invalid grade - must be greater than or equal to 0'
  3. Define grades = [80, 0, 90, 100, 70]
  4. Print the result of avg_grades(grades)

In [ ]:

def avg_grades(grades):

total = 0

for grade in grades:

# INSERT YOUR ASSERT STATEMENT HERE

total += grade

return total / len(grades)

# INSERT YOUR CODE HERE

Python Testing using unittest

IMPORTANT: To Run unittest in Jupyter Notebook you have to modify unittest.main()

See https://medium.com/@vladbezden/using-python-unittest-in-ipython-or-jupyter-732448724e31

Question 3

  1. Use the function namedlbs_to_stones(code provided)
  2. Useunittestto test this funtion (requires 'import' statement)
  3. Define a class Tests(unittest.TestCase)
  4. Define a test method named 'test_lbs_to_stones(self)'
  5. Use assertEqual to verify lbs_to_stones(140) is equal to 10
  6. Add ifname== 'main' ... lines (see IMPORTANT note below for syntax)

# IMPORTANT: To run unittest in Jupyter you must make this change:

# if __name__ == '__main__':

# unittest.main()

#

# ... TO ...

# if __name__ == '__main__':

# unittest.main(argv=['first-arg-is-ignored'], exit=False)

#

"""

Function that need to be unit tested

"""

def lbs_to_stones(lbs):

return lbs/14

# INSERT YOUR CODE HERE

Python Debugging with Print()

Using simple print() commands is often all that's needed when debugging a problem

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

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions

Question

Explain why a total return swap can be useful as a financing tool.

Answered: 1 week ago

Question

22 Production implementation 492

Answered: 1 week ago