Friday, February 1, 2019

Odd and Even in a list

  • Problem Description

    Python Program to Put Even and Odd elements in a List into Two Different Lists

    Input 
    First Line is the Number of Inputs
    Second line is the elements of the list

    Output
    Print the Even List and Odd List
  • CODING ARENA
  • a=[]
    n=int(input())
    for i in range(1,n+1):
        b=int(input())
        a.append(b)
    even=[]
    odd=[]
    for j in a:
        if(j%2==0):
            even.append(j)
        else:
            odd.append(j)
    print("The even list",even)
    print("The odd list",odd)
  • Test Case 1

    Input (stdin)
    5
    
    67 
    
    43 
    
    44 
    
    22 
    
    455
    
    
    Expected Output
    The even list [44, 22]
    
    The odd list [67, 43, 455]
  • Test Case 2

    Input (stdin)
    3
    
    23 
    
    44 
    
    99
    
    
    Expected Output
    The even list [44]
    
    The odd list [23, 99]

No comments:

Post a Comment