Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
comparison in lists
#1
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}')
Reply
#2
I think you meant line 18
maior = lista[1]
to be
maior = lista1[1]
Reply
#3
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:
Reply
#4
Thanks guys, i'm very inattentive, i forgot the 1 in 'lista1'
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020