Why this code not work

porque este codigo nao funciona? recebo msg:

if salarios > 1250:
^^^^^^^^^^^^^^^
TypeError: ‘>’ not supported between instances of ‘dict’ and ‘int’

code:

salarios = {
    'Pedro': 1260,
    'Jose': 2500,
    'Henrique': 1800,
    'Daniel': 2100,
    'Fernando': 1000,
    'Marcos': 600,
}

if salarios > 1250: # here is the problem
    aumento = ((salarios.values() * 10) / 100)
    salarios = salarios.append(aumento) # falta: atualizar o valor na lista de salarios
    print(salarios)
else:
    aumento = ((salarios.values() * 15) / 100)
    salarios = salarios.append(aumento) # falta: atualizar o valor na lista de salarios
    print(salarios)

I’m using Google Translate:

Porque você está verificando o “dicionário” como um valor único. Um dicionário tem muitos valores.

O que exatamente você deseja fazer com esta instrução? Verificar se alguém tem salário superior a 1250?

The error pointed at this line of code.

What do you think should happen when this code runs?

In particular: do you think that salarios is greater than 1250? What should that actually mean? Look closely at the previous code. What kind of thing is stored in salarios (hint: the error message also tells you this)? Does it make sense to you, to compare that to a number? How should that kind of comparison work?

I guess that you used a dictionary to store the salary for several people. And I guess that you want to do a calculation with someone’s salary. But - whose salary?

1 Like

As the error message says, you can’t compare a dict against an int.

You need to iterate over the dict and perform the comparisons and calculations on each entry.

Exactly that im trying to do

OK, let’s assume there is one worker that has got >1250 salary. Do you want then update his/her salary only or update salaries for everyone?