"None" instead of [1,1,1,1]

Asked

Viewed 49 times

0

I’m making a problem that works like this: For example, suppose a team of 4 telemarketing vendors should make 6 calls, the times being 5, 2, 3, 3, 4, 9. As initially no vendor is busy, the first seller will make the 5 minute call, the second seller the 2-minute call and the number 3 and 4 sellers will make 3-minute calls. As the second seller will finish his call before the others, he will make the fifth call, of 4 minutes and, finally, the third seller (whose time is equal to the fourth seller, but his identification number is lower) will make the sixth call, of 9 minutes.

The function has to return a list with the number of calls each seller made. In the example above, it would have to return [1,2,2,1].

My code is for now only assessing whether the number of sellers is equal to the number of calls or higher. However, I am printing an example where that number is equal, and it is returning "None" instead of [1,1,1,1].

def ligacoes(n,l):
"Retorna uma lista que contem quantas ligacoes cada vendedor fara, seguindo as regras"
resultado = []
#v = numero de identificacao dos vendedores
    if n == len(l):
        for n in range(len(l)):
            resultado = resultado + [1]
    if n > len(l):
        for n in range(len(l)):
            resultado = resultado + [1]
        resultado = resultado + [0]

print ligacoes(4,[3,3,4,5])
  • 1

    fix code indentation - as is not possible to know what is inside the function or not.

  • sorry, I didn’t even notice that I wasn’t thinking. it was time to paste here on the site. I already packed.

  • 2

    @W.Lucas is missing return resultado

  • True raccoon, I forgot the Return. what a beginner error jesus kkkk thank you so much!! did not give the result I wanted but at least did not give None (I think now I know fix)

  • voting to close on account of it being a trivial error (squaring of the Return) already understood by A.P.

No answers

Browser other questions tagged

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