Friday, February 1, 2019

Sorted Order

  • Problem Description

    Write a program that reads integers from the user and stores them in a list. Your program should continue reading values until the user enters 0. Then it should display all of the values entered by the user (except for the 0) in order from smallest to largest, with one value appearing on each line. Use either the sort method or the sorted function to sort the list.
  • CODING ARENA
  • x=[]
    count=0
    while True:
        a=int(input())
        if(a==0):
            break
        else:
            x.append(a)
    x.sort()
    for i in range(len(x)):
        print(x[i])
  • Test Case 1

    Input (stdin)
    5
    
    44
    
    33
    
    25
    
    78
    
    23
    
    345
    
    76
    
    0
    
    
    Expected Output
    5
    
    23
    
    25
    
    33
    
    44
    
    76
    
    78
    
    345
  • Test Case 2

    Input (stdin)
    15
    
    144
    
    133
    
    125
    
    178
    
    123
    
    1345
    
    376
    
    0
    
    
    Expected Output
    15
    
    123
    
    125
    
    133
    
    144
    
    178
    
    376
    
    1345

No comments:

Post a Comment