Answers for "if elif statement python"

2

if ,elif, else in python

# if,elif,else in statement.
m=1
n=2
p=3
if n<m:
    print('n is greater than m')#(n>m,hence not satisfied)
elif p!=m+n:
    print('p is not equal to  sum of m and n')#(p==m+n, hence not satisfied)
else:
    print('not satisfied')
output:
not satisfied
................................................................................
Posted by: Guest on November-26-2021
17

elif python

The elif statement allows you to check multiple expressions for TRUE 
and execute a block of code as soon as one of the conditions evaluates
to TRUE. Similar to the else, the elif statement is optional. However,
unlike else, for which there can be at most one statement, there can 
be an arbitrary number of elif statements following an if.

if expression1:
   statement(s)
elif expression2:
   statement(s)
elif expression3:
   statement(s)
else:
   statement(s)
Posted by: Guest on April-17-2020
7

python if elif

num = 20
if num > 30:
  print("big")
elif num == 30:
  print("same")
else:
  print("small")
#output: small
Posted by: Guest on May-09-2020
1

python else elif

>>> a = 5
>>> if a > 5:
...     a = a + 1
... elif a == 5:
...     a = a + 1000
... else:
...     a = a - 1
... 
>>> a
1005
Posted by: Guest on February-19-2020

Python Answers by Framework

Browse Popular Code Answers by Language