Question
PYHTON3; DO NOT IMPORT ANY PACKAGES Write assert statements in this function, so that whenever the input is invalid, the corresponding assert statement will throw
PYHTON3; DO NOT IMPORT ANY PACKAGES
Write assert statements in this function, so that whenever the input is invalid, the corresponding assert statement will throw assertion error. Return the num parameter if all assert statements passed.
The requirement for all parameters are as follows:
-
num: Must be a positive integer
-
lst: Must be a list of numeric values (int or float), the sum of this list must be strictly less than 20
-
args: All must be float, and at least one of them should be between -5.0 and 5.0 (both inclusive)
-
kwargs: For all values, they must be string, with length greater than 1, and the first character and the last character must be the same
Requirements: assert statements
*** When a question requires assert statements: write assert statements to prevent any input that may corrupt your code, including arguments in invalid type, and arguments that do not fit the logic***
Notes:
-
You can write assert statements at any place within the function, including within a loop.
-
The built-in functions all() and any() will help if you prefer writing one-liner assert statements with list comprehension.
def assert_playground(num, lst, *args, **kwargs):
"""
>>> assert_playground(15, [9.5, 1], -3.1, 9.2,
... s1="Jessie J", s2="racecar")
15
>>> assert_playground(2.0, [9.5, 1], -3.1, 9.2,
... s1="Jessie J", s2="racecar")
Traceback (most recent call last):
AssertionError
>>> assert_playground(15, [4, 7.0, 9.1], -3.1, 9.2,
... s1="Jessie J", s2="racecar")
Traceback (most recent call last):
AssertionError
"""
# YOUR CODE GOES HERE #
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