Python Forum
I don't undestand why my code isn't working.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I don't undestand why my code isn't working.
#1
treinamentos = [
{'treinamento':'Scrum','moedas':30},
{'treinamento':'Data Science','moedas':40},
{'treinamento':'Gestão de Projetos','moedas':50},
{'treinamento':'Marketing','moedas':30},
{'treinamento':'Cloud','moedas':20},
{'treinamento':'Blockchain','moedas':10},
{'treinamento':'Python','moedas':30}]

pedidos = ['Data Science','Scrum','Gestão de Projetos','Marketing','Cloud','Python','Python','Python',
'Scrum','Data Science','Gestão de Projetos','Marketing','Data Science','Gestão de Projetos',
'Python','Marketing','Data Science','Gestão de Projetos','Data Science','Gestão de Projetos','Data Science']

lista_pedidos = sorted(set(pedidos))

for a in lista_pedidos:
  for b in treinamentos:
    if a == b['treinamento']:
      b['qtde'] = pedidos.count(a)
    else:
      b['qtde'] = 0
print(treinamentos)
Saída:
Output:
[{'treinamento': 'Scrum', 'moedas': 30, 'qtde': 2}, {'treinamento': 'Data Science', 'moedas': 40, 'qtde': 0}, {'treinamento': 'Gestão de Projetos', 'moedas': 50, 'qtde': 0}, {'treinamento': 'Marketing', 'moedas': 30, 'qtde': 0}, {'treinamento': 'Cloud', 'moedas': 20, 'qtde': 0}, {'treinamento': 'Blockchain', 'moedas': 10, 'qtde': 0}, {'treinamento': 'Python', 'moedas': 30, 'qtde': 0}]
buran write Jun-17-2021, 03:00 PM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply
#2
you reset qtde to 0 every time when a != b['treinamento']
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Jun-17-2021, 03:03 PM)buran Wrote: you reset qtde to 0 every time when a != b['treinamento']

It makes sense, it's working now. Thanks
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 960 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 891 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,016 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,080 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 1,929 Mar-21-2022, 10:12 AM
Last Post: End3r
  code is not working , can anybody help? RandomPerson69 4 2,909 Mar-22-2021, 04:24 PM
Last Post: deanhystad
  Short code for EventGhost not working Patricia 8 3,685 Feb-09-2021, 07:49 PM
Last Post: Patricia
  Code no longer working yk303 14 10,176 Dec-21-2020, 10:58 PM
Last Post: bowlofred
  autocomplete working code sample not working... aviper4u 0 1,640 Oct-24-2020, 03:04 AM
Last Post: aviper4u
  code not working, NameError: name 's' is not defined ridgerunnersjw 4 3,820 Oct-05-2020, 07:03 PM
Last Post: buran

Forum Jump:

User Panel Messages

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