Doubt about Python List Code

Asked

Viewed 37 times

-4

Can anyone help me? I’m trying to print the 1st, 2nd and 3rd place message on the screen, but I’m not getting it. Someone has an idea?

lista = []
flag = False

for x in range(3):

    tamanho = len(lista)

    n = float(input("Digite um número inteiro: "))

    if( tamanho > 0 ):

        for y in range( tamanho ):

            if ( n >= lista[y] ):

                lista.insert( y, n )


                break

    if((x == 0) or (flag == False)):

        lista.append( n )

    else:

        flag = False

          print(lista)

          print("Primeira Posição:", "Segunda Posição:", "Terceira Posição:", )

1 answer

0


The question was not very clear. What would be these "1st, 2nd and 3rd place"? Would be the numbers inserted in order of insertion?

If yes, the following code is functional:

lista = []

for x in range(3):
    tamanho = len(lista)
    n = float(input("Digite um número inteiro: "))
    if((x < 3)):
        lista.append(n)

print("Primeira Posição: " + str(lista[0]) + " Segunda Posição:" + str(lista[1]) + " Terceira Posição:" + str(lista[2]))
  • That, I need a clear message to show which number was in which position!

  • You’ve helped me, thanks bro :D

Browser other questions tagged

You are not signed in. Login or sign up in order to post.