else if statement 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: if syntax in python
variable_name = input("y/n? >> ")
if variable_name == "y":
print("That's good! :) ")
elif variable_name == "n":
print("That's bad! :( ")
else:
print("You blow up for not following my instructions. Detention forever and get lost!")
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: python if else
if 10 > 5:
print("Ten is greater than five")
if 10 < 5:
print("Ten is less than five")
if 10 < 5:
print("Ten is less than five")
else:
print("Ten is greater than five")
if 10 < 5:
print("Ten is less than five")
elif 10 > 5:
print("Ten is greater than five")
if 10 < 5:
print("Ten is less than five")
elif 10 > 5:
print("Ten is greater than five")
else:
print("Ten isn't greater or less than five")
Example 5: else if python
if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
else:
statement(s)
Example 6: if statement python
x=1; y=0; z=0;
if 1 in {x,y,z}:
print('At least one variable is equal to 1')