Put N values in order

0

I need to make a program that reads n numbers (undetermined quantity) and then put them in order. The stop condition is the number 0.

I thought about throwing these values to a list and then sorting them. I made a while loop, however, obviously it will only save the last value.

    
asked by anonymous 24.12.2017 / 01:28

1 answer

0
Good afternoon, how are you? Dude, it depends on the way you're doing things, I'm without python on this computer, but I believe this code will do what you're thinking, I hope it returns if it did, or not, right. I'll be waiting.

    lis_ord = []

    while True:

    num = int(input("Por favor, adicione um número a lista [insira 0 para sair]: "))

    if num > 0 or num < 0:
        lis_ord.append(num)
        lis_ord.sort
        print("O número foi adicionado com sucesso, sua lista é:")
        print(lis.ord)

    elif num == 0:
        print("Obrigado por usar o programa. Encerrando.")
        break

    else:
        print("Comando inválido. Use apenas números.")

The above code block should work as follows:

Create a list and link it to the variable lis_ord; While true, it asks the user to provide an input, stored in the variable num, then it organizes the list from the smallest to the largest, the printa that the number was added, and displays the list in its current state; If the input is greater or less than zero, it appends the lis_ord list; If the input is zero, it terminates the program; If the input is a STRING, or a FLOAT, for example, the invalid command line, and returns to the input of the user;

Maybe something is wrong, because I did not have the test, but, whatever, return with an answer and I'll try to help again. Placing your code would also be of great help in understanding where the error is occurring. Hope to have helped, hugs.

    
24.12.2017 / 19:42