python if else statement example

Example 1: 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 2: else if python

if expression1:
   statement(s)
elif expression2:
   statement(s)
elif expression3:
   statement(s)
else:
   statement(s)

Example 3: if else python

if condition:
   result
elif condition:
   result
else:
   result

Example 4: else if python

name = input("What's your name? \n") # Asks user for a name

# Following if order:
# first program checks if the if is true
# next program lists down the elifs (or else ifs) in the order 
# in which they are listed
# Lastly, if there is an else, program does whatever is inside
# of there.

if name == "Aguy12": # First checks if they answered "Aguy12"
  print("Wait a second...")
elif name == "Aguy11": # Then checks if they answered with "Aguy11"*
  print("Now that's definitely not true")
else: # If none of those are true greets the person accordingly
  print(f"Hello, {name}!")
  
# * ONLY IF THE IF STATEMENT IS NOT TRUE

Example 5: Python If ... Else

a = 33
b = 33
if b > a:
  print("b is greater than a")
elif a == b:
  print("a and b are equal")