cont.....
of Python #3-For Loop and While Loop In Python
Syntax:
if (condition):
statement
else:
statement
Example:
marks = 41
if marks < 40 :
print "failed"
else
print "passed"
Output:
passed
of Python #3-For Loop and While Loop In Python
What is if Statement?
An if statement is Selection statement. It is also called as Decision Making Statement.
Syntax:
if (condition):
statement
Example:
marks = 39
if marks < 40 :
print "failed"
Output:
failed
Note Worthy: As i said previously Python uses indentation to make code blocks. So the statement should me done as it is in the above syntax.
_________________________________________________________________________________
Don't forget to try here!
____________________________________________________________________________
if else:
if (condition):
statement
else:
statement
Example:
marks = 41
if marks < 40 :
print "failed"
else
print "passed"
Output:
passed
_________________________________________________________________________________
Elif Statement :
Example:
marks =50
if marks < 40 and marks >=0:
print "Failed"
elif marks < 60 and marks >=40:
print "C Grade"
elif marks < 80 and marks >=60:
print "B Grade"
elif marks <=100 and marks>=80:
print "A Grade"
else:
print "Invalid mark Statemtent"
Output:
C Grade
_________________________________________________________________________________
Tech Bird
Comments
Python Online Training