Question
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
- Create a function namedfeet_to_inches(ft)
- 1.1 Add assert to check 'ft' is anintwith error message = 'feet is not an integer'
- 1.2 Convert 'ft' to 'inches'
- 1.3 Return the value of 'inches'
- Call feet_to_inches(ft) with ft = 10
- Call feet_to_inches(ft) with ft = 5
- Call feet_to_inches(ft) with ft = 0
- Call feet_to_inches(ft) with ft = 'ten'
In [ ]:
def feet_to_inches(ft)
Question 2
- Use the function namedavg_grades(grades)provided
- 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'
- Define grades = [80, 0, 90, 100, 70]
- 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
- Use the function namedlbs_to_stones(code provided)
- Useunittestto test this funtion (requires 'import' statement)
- Define a class Tests(unittest.TestCase)
- Define a test method named 'test_lbs_to_stones(self)'
- Use assertEqual to verify lbs_to_stones(140) is equal to 10
- 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started