CodeSolved

A comprehensive source of programming questions and exercises

Separate pair numbers and individual list

Practice Easy 194/ Download 2836 Views

Write a function that receives a list of numbers and creates 2 lists for pair and individual numbers and prints on output

Example

myfun([1,2,3,4])
output:
[1,3]
[2,4]

14 Answers

This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error'
alert(msg) 
This answer is only visible to premium members
This answer is only visible to premium members

This answer is only visible to premium members

Subscription is currently unavailable.
def adad_z_f(i):
    z=[]
    f=[]
    for num in numbers:
     if num%2==0:
        z.append(num)
     else:
         f.append(num)
    print(z,f)
numbers=[1,2,3,4,5,6,7,8]
adad_z_f(numbers)
Maryam.n Download Python
def hazf(x):
    even = []
    odd = []
    for i in range(len(x)):
        if x[i]% 2 == 0:
            even.append(x[i])
        else:
            odd.append(x[i])
    return even, odd
lists = []
even = []
odd = []
while True:
    x = int(input('adad ra vared konod ya jahat moshahede faghat 0 bezanid: '))
    if x == 0 :
        even,odd = hazf(lists)
        print(f'even: {even}\nodd: {odd}')
        break
    lists.append(x)
def som_of_odds():
    o=[]
    z=[] 
    while 1: 
     i=int(input(':'))
     if i==0:
        break
     if i%2==0:
           z.append(i)
     else:
            o.append(i)
            print(o,z)
print(som_of_odds())
Maryam.n Download Python
def print_eo_list():
    eo_list = []
    even_list = []
    odd_list = []
    while True:
        eo_nums = int(input("Enter a number Or enter zero(0) to exit: "))
        eo_list.append(eo_nums)
        if eo_nums % 2 == 0:
            even_list.append(eo_nums)
        elif eo_nums % 2 != 0:
            odd_list.append(eo_nums)
        if eo_nums == 0:
            print(f"even and odd list => {eo_list}\neven list => {even_list}\nodd list => {odd_list}")
            break
print_eo_list()
from os import system
lst = []
odd = []
even = []
system('cls')
while True:
    num = int(input('Enter number (0 = Exit) : '))
    if num == 0:
        break
    lst.append(num)
    system('cls')
for i in lst:
    if i%2 == 0:
        even.append(i)
    else:
        odd.append(i)
lst.copy
system('cls')
print(f'odd number is {odd}')
print(f'even number is {even}')
adad_zoj = []
adad_fard = []
while 1:
    number = int(input("please enter a number:" ))
    if number == 0:
        break
    elif number % 2 ==0:
        adad_zoj.append(number)
    else:
        adad_fard.append(number)
print("adade zoj = ", adad_zoj)
print("adade fard = ", adad_fard)

num_lst = [1, 2, 3, 4, 5, 6, 7, 8, 9]
def odd_even(num_lst):
    odd_lst = []
    even_lst = []
    for item in num_lst:
        if item % 2 != 0:
            odd_lst.append(item)
        else:
            even_lst.append(item)
    print(f"odd numbers list=> {odd_lst}")
    print(f"even numbers list=> {even_lst}")
odd_even(num_lst)
Behcoder Download Python
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

Related content

Detection using AI
×
×
Close