IF ELSE IF IN PYTHON code example
Example 1: 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)
Example 2: python if
if num<5:
print('Num less than 5')
elif 5<= num <=9:
print('Num between 5 and 9')
else:
print('Num more than 9')
Example 3: else if python
word = input('Word: ')
if word == 'hello':
print('world')
elif word == 'world':
print("Hey, that's my line >:(")
else:
print("Hey buster you gonna say hello or not?")
Example 4: if statement in python
answer = input(":")
if answer == "lol":
print("haha")
else:
print("not haha")
exit()
please note that the exit() command is optional and is not necessary.
Example 5: if statement python
x=1; y=0; z=0;
if x==1 or y==0:
if z=0 and x=1:
print('Useless conditions satisfed!')
Example 6: Python If ... Else
a = 200
b = 33
if b > a:
print("b is greater than a")
elif a == b:
print("a and b are equal")
else:
print("a is greater than b")