python else code example
Example 1: python if statement
usrinput = input(">> ")
if usrinput == "Hello":
print("Hi")
elif usrinput == "Bye":
print("Bye")
else:
print("Okay...?")
Example 2: if else python
# IF ELSE ELIF
print('What is age?')
age = int(input('number:')) # user gives number as input
if age > 18:
print('go ahead drive')
elif age == 18:
print('come personaly for test')
else:
print('still underage')
Example 3: 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 4: or statement python
if x==1 or y==1:
print(x,y)
Example 5: 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 6: else if python
word = input('Word: ') # This will ask you to print a word
if word == 'hello': # <- If your response is: 'hello'
print('world') # <- It will output: 'world'
elif word == 'world': # If the response is: 'world'
print("Hey, that's my line >:(") # It will print this
else:
print("Hey buster you gonna say hello or not?")
# If sombody prints ANYTHING ELSE other than 'hello' or 'world'
# It will output that print statment above!
#Hope this helped you!