primary block will be ‘if’, this will evaluate the c.e and if it is true,
it will execute code-block under ‘if’ statement. if the c.e turns out to false, then it will go to first ‘elif’ block
‘elif’ c.e is validated and if it is True, the code-block under this ‘elif’ will be executed, if not, it will go to next elif block and so on till it validates all the elif blocks.
if none of the ‘if’, ‘else’ c.e if turns to be True, then else block will be executed
flow chart of if-elif-else:
if-elif-else
Example
z = int(input('enter marks:'))
if z>80: print('first class with distinction')
elif z>60and z<80: print('first class')
elif z>35and z<60: print('second class')
elif z<35: print('fail')
And the output is:
enter marks:46 second class
Nested if
if inside the if
flow chart of Nested if:
nested if
Example
marks = int(input('enter marks:'))
c = time.time() a = time.time() if marks>=35: if marks<60: print('second class') elif marks>60and marks<80: print('first class') else: print('fwd') else: print('fail')
No comments:
Post a Comment