Odd and Even using Append in python

How to Separate Odd and Even Numbers in Python

When you perform division operation on any number by 2 then it may give ‘0’ or ‘1’ if remainder is ‘0’ then that is an even number. if reminder ‘1’ then that is an odd number.

Example:

2%2 = 0 #Remainder is ‘0’ so it is even number

3%2 = 1 #Remainder is ‘1’ so it is odd number

Write an algorithm for Odd and Even Number in Python

step1: Start

step2: def variable(ABC):

step3: Take an empty set of odd and even

step4: Use loop in the number you given

step5: Check the condition if it’s true then append in even else odd 

step6: Return output

step7: Enter the number 

step8: print(def_variableName(pass_number))

step9: end

Example:

In this example we will see, how can we separate odd and even number using the append() method.

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 and even numbers list:',odd_even(number))

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
Odd and even numbers list: [[1, 3, 15, 7, 9], [2, 12, 6, 8]]

Process finished with exit code 0

Learn Complete Python In Simple Way

Click on enroll Button and watch the sample video then Go for Paid if you like.

Recommended Post:

Get Salesforce Answers

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



1 thought on “Odd and Even using Append in python”

Leave a Comment