Python Tutorial

Showing posts with label if else elif. Show all posts
Showing posts with label if else elif. Show all posts

Wednesday, August 18, 2010

python If else

'''
    This code use python if else syntax
'''
n=16
if n%2==0:
    print n," is a even number"
elif n%5==0:
    print n," is divisible by 5"
else:
    print n," is a odd number"

if n%2==0 and n%4==0:
    print n," is divided by both 2 and 4"

if n%2==0 or n%6==0:
    print n," is divided by 2 or 6"


Output:
16  is a even number
16  is divided by both 2 and 4
16  is divided by 2 or 6