0
1.2kviews
Explain Conditional statement structure in python with example.
1 Answer
written 2.6 years ago by |
Conditional expressions and conditional constructs are features ofa programming language, which perform different computations or actions depending on whethera programmer-specified Boolean condition evaluates to true or false.
If Statements
Syntax:
if expression:
statement(s)
Example:
x=15
if x>0:
print('Positive Value..")
If-else Statements
Syntax:
if expression:
statement(s)
else:
statement(s)
Example:
age=27
if age>18:
print('You can drive')
else:
print('you can not drive)
If-else if-else Statements
Syntax:
if expression:
statement(s)
elif expression:
statement(s)
else:
statement(s)
Example:
X=15
ifx>0:
print('Positive Value..')
elif x<0:
print('Negative Value..)
else:
print('value is zero')
Nested if Statement
Syntax:
if expression:
statement(s)
if expression:
statement(s).
else:
statement(s)
else:
statement(s)
Example:
x=15
If x>0
print(Positive Value)
if 10:
print("Value is less then 10)
else
print(Value is more than 10)
elif x<0
print('Negative Value)
else:
print('value is zero')