You don’t need to sort the list with each data entry, you can do this only at the end, because the methods sort
and reverse
work with all data from the list:
numeros = []
for i in range(0,3):
numeros.append(int(input('Digite um numero: : ')))
numeros.sort()
numeros.reverse()
print('a ordem eh:',numeros)
See online: https://repl.it/repls/DependableDopeyDecompiler
It is also possible to sort the list with only one line, using the parameter reverse
of the method sort
:
numeros = []
for i in range(0,3):
numeros.append(int(input('Digite um numero: : ')))
numeros.sort(reverse=True)
print('a ordem eh:',numeros)
See online: https://repl.it/repls/SwelteringAttractiveAttribute
If you only need to display the sorted list, you could also use the function sorted
, which, unlike the methods used, receives a list and does not change it, it returns a new ordered list:
numeros = []
for i in range(0,3):
numeros.append(int(input('Digite um numero: : ')))
print('a ordem eh:',sorted(numeros, reverse=True))
See online: https://repl.it/repls/VitalFrightenedApplicationsoftware
Thank you! You helped a lot
– Thais Tavares