The following variable is defined: height = 40 What will happen when executing the following code: assert height > 0
The following variable is defined:
height = 40
What will happen when executing the following code:
assert height > 0
a. The assert statement checks if the value of the height varaible is greater than 0. If the condition is true (and in this case it is – it returns True), an AssertionError will be raised.
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), no error will be raised and code execution continues on the next line(if any).
c. The assert statement checks that the value of the height variable is greater than 0. if the condition is true (and in this case it is – it returns True), no error will be raised and code execution continues on the next line (if any).
c. The assert statement checks that the value of the height variable is greater than 0. if the condition is true (and in this case it is – it returns True), no error will be raised and code execution continues on the next line (if any).
Explanation:
Assert statements are a convenient way to insert debugging assertions into a program:
assert_stmt ::= "assert" expression ["," expression]