Python Forum
comparison in lists - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: comparison in lists (/thread-18252.html)



comparison in lists - Renatoluz - May-10-2019

Hi, i'm a beginner in python and programmation, and i have a doubt about comparison in lists, I have this error

Error:
TypeError: '>' not supported between instances of 'int' and 'list'
but i can try three times after this, so that means it goes into my IF block, right ?
the error is in this line, according to pycharm.
        if lista1[1] > maior:
            maior = lista[1]
the code is written in Portuguese, i hope you can understand.
Thanks

lista = []
lista1 = []
cont = 's'
maior = menor = pessoas = contador = 0

while cont in 'Ss':
    lista1.append(str(input(' NOME : ')))
    lista1.append(int(input(' PESO : ')))
    lista.append(lista1[:])
    pessoas += 1
    contador += 1
    print(lista1[1])  # 38 88 11
    if contador == 1:
        maior = lista1[1]
        menor = lista1[1]
    else:
        if lista1[1] > maior:
            maior = lista[1]
        if lista1[1] < menor:
            menor = lista1[1]
    lista1.clear()

    cont = str(input('Quer continuar ? [S/N]'))

print(f'Foram cadastradas {pessoas} pessoas ')
print(lista)
print(f'o mais pesado pesa {maior} e o mais leve pesa {menor}')



RE: comparison in lists - Yoriz - May-10-2019

I think you meant line 18
maior = lista[1]
to be
maior = lista1[1]



RE: comparison in lists - woooee - May-10-2019

The error message is self explanatory
Quote:TypeError: '>' not supported between instances of 'int' and 'list'
This happens when maior is zero and lista1[1] is a list (according to this line print(lista1[1]) # 38 88 11). Print both to answer the question yourself.
if lista1[1] > maior:



RE: comparison in lists - Renatoluz - May-11-2019

Thanks guys, i'm very inattentive, i forgot the 1 in 'lista1'