Sitemap
Bhavitha Cherukuri

Bhavitha Cherukuri

My passion for writing motivated me to start writing blogs and the content within is written in a simple and easy format. so that readers can understand easily.

#PYTHON(DAY14)

2 min readMay 10, 2023

--

Continuation of conditional statements

if-elif-else

  • 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

Get Bhavitha Cherukuri’s stories in your inbox

Join Medium for free to get updates from this writer.

Example

z = int(input('enter marks:')) 


if z>80:
print('first class with distinction')

elif z>60 and z<80:
print('first class')

elif z>35 and 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>60 and marks<80:
print('first class')
else:
print('fwd')
else:
print('fail')

d = time.time()
b = time.time()

And the output is:

enter marks:67
first class

--

--

Bhavitha Cherukuri
Bhavitha Cherukuri

Written by Bhavitha Cherukuri

My passion for writing motivated me to start writing blogs and the content within is written in a simple and easy format. so that readers can understand easily.