multiple if statements python code 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: python if elif

num = 20
if num > 30:
  print("big")
elif num == 30:
  print("same")
else:
  print("small")
#output: small

Example 3: if else statement with multiple conditions python

if( (5 ** 2 >= 25) and (4 * 2 < 8) or (35 / 7 > 4) ):
	print("Booleans make If more powerful!")

Example 4: if and elif

'''In this program, we input a number
check if the number is positive or
negative or zero and display
an appropriate message
This time we use nested if statement'''

num = float(input("Enter a number: "))
if num >= 0:
    if num == 0:
        print("Zero")
    else:
        print("Positive number")
else:
    print("Negative number")

Example 5: if and elif

if test expression:
    Body of if
elif test expression:
    Body of elif
else: 
    Body of else

Tags:

Java Example