Question
I am confused on how to create a function then add an assert statement, then use that statement to create a formula. Please help Create
I am confused on how to create a function then add an assert statement, then use that statement to create a formula. Please help
Create a function named yards_to_meters(yds) 1.1 Include an assert to check 'yds' is an int with error message text = 'yds value is not an integer' 1.2 Convert 'yds' to 'meters' 1.3 Return the value of 'meters'
print("QUESTION 1 - ANSWERS")
# TEST CASE 1 try: meters = yards_to_meters(100) except AssertionError as msg: print("TEST1: ", "yards_to_meters(100) failed") print("TEST1: ", msg) else: print("TEST1: ", "yards_to_meters(100) passed") print("TEST1: METERS = ", meters) print()
# TEST CASE 2 try: meters = yards_to_meters(60.5) except AssertionError as msg: print("TEST2: ", "yards_to_meters(100) failed") print("TEST2: ", msg) else: print("TEST2: ", "yards_to_meters(100) passed") print("TEST2: METERS = ", meters) print()
# TEST CASE 3 try: meters = yards_to_meters('100') except AssertionError as msg: print("TEST3: ", "yards_to_meters(100) failed") print("TEST3: ", msg) else: print("TEST3: ", "yards_to_meters(100) passed") print("TEST3: METERS = ", meters) print() # TEST CASE 4 try: meters = yards_to_meters(40) except AssertionError as msg: print("TEST4: ", "yards_to_meters(100) failed") print("TEST4: ", msg) else: print("TEST4: ", "yards_to_meters(100) passed") print("TEST4: METERS = ", meters) print()
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