CodeSolved

Solved Programming Questions & Exercises

Separate pair numbers and individual list

Practice Easy 194/ Download 3874 Views Most popular

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]

15 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 separate_even_odd(numbers):
    # Empty lists for couple and individual numbers
    even_numbers = []
    odd_numbers = []
    
    # Survey on the input list
    for number in numbers:
        if number % 2 == 0:
            even_numbers.append(number)  # If the number is pair, it will be added to the list of couples
        else:
            odd_numbers.append(number)   # If the number is an individual, the individual is added to the list of individuals
    
    # Printing the couple and individual lists
    print(odd_numbers)
    print(even_numbers)

# Example of the use of function
separate_even_odd([1, 2, 3, 4])
Mma123 Download Python
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()
Zehsanz274 Download Python
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)

<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close