Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

  1. num: Must be a positive integer

  2. lst: Must be a list of numeric values (int or float), the sum of this list must be strictly less than 20

  3. args: All must be float, and at least one of them should be between -5.0 and 5.0 (both inclusive)

  4. 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:

  1. You can write assert statements at any place within the function, including within a loop.

  2. 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

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

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions