Important Notice:

Using assert Statement

Using assert Statement

20 views 1 min read
Program 18: Using assert Statement
 
 
age = int(input("Enter your age: "))

assert age >= 18, "Age must be 18 or above"

print("You are eligible.")

Output 1:

Enter your age: 20
You are eligible.

Output 2:

Enter your age: 15
Traceback (most recent call last):
AssertionError: Age must be 18 or above

Explanation:
assert condition को check करता है। Condition True होने पर program आगे चलता है और False होने पर AssertionError आता है।

Related Notes