Odd and Even using if condition in python


Odd and Even using if condition in python

Odd and Even by using def in Python way–>1

def odd_even(num):
    odd=[]
    even=[]
    for i in num:
        if i%2 == 0:
            even.append(i)
        else:
            odd.append(i)
    output_num=[odd,even]
    return output_num
number=[1,2,3,12,15,6,7,8,9]
print(odd_even(number))

Odd and Even by using def and if way–>2

def odd_even(num):

    if num%2==0:
        return "even"    else:
        return "odd"number=int(inPut("enter any number:"))
print(odd_even(12))

Odd and Even By using def in Python way —–>3


def odd_even(num):
    if num%2==0:
        return "even"    
    return "odd"
numb=input("enter any no:")
print(odd_even(numb))

Odd and even in Python way—>4

def odd_even(num):
    if num%2==0:
        return True
    return False
print(odd_even(112))
 

Check is Even or not in Python shortcut way—>5

 
def is_even(num):
    return num%2==0
print(is_even(11))

Odd and Even using if condition in python

Have any Question or Comment?

One comment on “Odd and Even using if condition in python

Leave a Reply

Your email address will not be published. Required fields are marked *

Categories

You have successfully subscribed to myprogrammingschool

There was an error while trying to send your request. Please try again.

My Programming School will use the information you provide on this form to be in touch with you and to provide updates and marketing.