odd and even number in python using list

#!/usr/bin/env python

#print even numbers from 1 to 50

a=range(1,50);
#print(a);

#print even numbers
evenNumbers=a[1::2]
print(evenNumbers)

print('\n')
#print odd number
oddNumbers=a[::2]
print(oddNumbers)

#check if 22 belong to even
#this is boolean function return true , false according to result

print (22 in evenNumbers)

#check if 23 belong to odd
print (23 in oddNumbers)
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s