The following variable is defined: height = -20 What will happen when executing the following code: assert height > 0, 'height must be positive'
The following variable is defined:
height = -20
What will happen when executing the following code:
assert height > 0, 'height must be positive'
a. The assert statement checks that the value of the height variable is greater than 0. If the condition is false (and in this case it is – it returns False), no error will be raised and code execution continues on the next line (if any).
b. The assert statement checks if the value of the height variable is greater than 0. If the condition is false (and in this case it is – it returns False) then an AssertionError will be raised without any additional message.
c. The assert statement checks if the value of the height variable is greater than 0. If the condition is false (and in this case it is – returns False) the AssertionError will be raised with the appropriate message ‘height must be positive’.
c. The assert statement checks if the value of the height variable is greater than 0. If the condition is false (and in this case it is – returns False) the AssertionError will be raised with the appropriate message ‘height must be positive’.
Explanation:
Assert statements are a convenient way to insert debugging assertions into a program:
assert_stmt ::= "assert" expression ["," expression]