Friday, February 1, 2019

Tom and Jerry

  • Problem Description

    Write a program to display the odd and even numbers using a separate list.

    Odd numbers should be in one list and even numbers should be in another list

    Input:

    1. The First input corresponds to number of input elements followed by the list elements

    Output:

    1. Even Numbers in a list
    2. Odd Numbers in a list

    Refer sample input and output for formatting specification. 

    All float values are displayed correct to 2 decimal places. 

    All text in bold corresponds to input and the rest corresponds to output.
  • 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(even)
    print(odd)
  • Test Case 1

    Input (stdin)
    5
    
    99
    
    46
    
    33
    
    75
    
    34
    
    
    Expected Output
    [46, 34]
    
    [99, 33, 75]
  • Test Case 2

    Input (stdin)
    9
    
    99
    
    46
    
    33
    
    75
    
    34
    
    4
    
    5
    
    6
    
    7
    
    
    Expected Output
    [46, 34, 4, 6]
    
    [99, 33, 75, 5, 7]

No comments:

Post a Comment