0
How do I make the user type positive and negative numbers in the same row and the list display them in order from the smallest to the largest, preferably not using loop?
Exemplo de números digitados
[1, 2, 3, 4, 5, -1, -2, -3, -4, -5]
Exemplo de como a saída deve ser:
[-5, -4, -3, -2, -1, 1, 2, 3, 4, 5]
For the user to enter the positive and negative numbers randomly where the list should organize them from the largest pro minor, the example I did was to output the code
– user141036
truth, lack of attention my kkkkk, but the Sort() method will sort anyway.
– Laís Godinho
edited the answer
– Laís Godinho
How does that code look without using loop? (for teaching purposes and understanding)
– user141036
the difference is that you would have to put a list.append(int(input())) for each item you want to add to the list
– Laís Godinho
How do you insert all the codes on the same line?
– user141036
I edited in response, to better see
– Laís Godinho
why are there so many list.append(int(input()))?
– user141036
was just to illustrate that you need one for each item you want to add (in the example you asked to use looping)
– Laís Godinho
Alex says, as Laís explained, this is perfect, but it would be illogical to do this operation without loop. Because then it would be a very bad code to write, unless it is a requirement not to use any kind of loop, which for me would not make sense since it makes our life as a programmer much easier.
– Robson Silva
@Laísgodinho, you could do it
lista = [ int(a) for a in input().split() ]
if I’m not mistaken. Then you have, again, the whole to play with– Jefferson Quesado
lista = input().split()
lista.sort()
print(lista)
It’s strange she shows the results like this: ['-2', '-3', '-3', '-6', '1', '3', '4', '5'], negative numbers are not in order like positive numbers– user141036