failed . append attribute when entering list entry - (Python)

Asked

Viewed 40 times

-2

I was able to leave my registration in loop that will be terminated only if the user type N or n.
After closing the registration the program displays the registration lists and draw list, however, when printing the register list, returns only the last name and registered value.
I need the program to return to me as an example below:

Registration List

Maria donated R $ 30,00
João donated R$20,00

To draw list this as I need, multiplying the names by the amount donated.
Ex:
[Mary, Mary, Mary, John, John]

does the program not recognize the statement list_cadastro.append([name,value])? how do I correct this failure?

follows the code:

    import random
    lista_sorteio = list()#lista que vai receber o nome para sorteio
    lista_cadastro = list() #lista que vai receber o cadastro

    while True: #loop de repetição para varios cadastros
     nome = str(input('Nome: ')).capitalize() #captura o nome do doador
     valor = int(input('Valor: R$')) #captura o valor doado
      print('') # inserir espaço
      chances = int(valor // 10)
      for c in range(chances):
          lista_sorteio.append([nome])
      alexa = str(input('INSERIR NOVO CADASTRO? [S/N] ')).strip().upper()[0] # sai do loop cadastro
      if alexa in 'Nn':
         break #encerra o loop digitando N
    print('') # inserir espaço
    print('LISTA DE CADASTRO:')
    for d in range(chances):
        lista_cadastro.append([nome, valor])
        print(f'{nome} doou R${valor:.2f};')  # mostra os nomes em 
    lista_cadastro
    print('')  # inserir espaço
    print('LISTA DE SORTEIO:')
    print(lista_sorteio) # mostra os nomes em lista_sorteio
    print('') # inserir espaço
    ganhador = random.choice(lista_sorteio) #realizar sorteio
    print('O ganhador do Sorteio é {[0]}'.format(ganhador)) #mostra o nome do sorteio

1 answer

0

If I understood what the goal was (increase the chances of those who collaborated more), it worked doing the end like this:

print('LISTA DE SORTEIO:')
for nom in lista_cadastro:
    nomeSorteio = int(nom[1] / 10)
    for c in range(nomeSorteio):
        lista_sorteio.append(nom[0])

print
print(lista_sorteio)
ganhador = random.choice(lista_sorteio)  # realizar sorteio
print('O ganhador do Sorteio é {}'.format(ganhador))  # mostra o nome do sorteio

I suggest we analyze the differences to see what was wrong..

  • thanks for the Epx reply, in this case, I imagined a reasoning in which I would perform all the entries and only then return the list on the screen: ex: REGISTRATION LIST XXXXXXXXX XXXXX DRAW LIST XXXXXXXXX, XXXXX, XXXXX WINNER XXXXXXX I can print the registration list, but I can’t print the draw list and it multiplies the name by the donated value. ex: registration list maria donated 30,00 joão donated 20,00 Giveaway list [Maria, Maria, Maria, João, João]

  • I changed the code, I got the return of the draw list multiplied by the value donated, but now the failure is the return of the registration list, in which does not return all registered items, returns only the last item, could help me in this failure?

Browser other questions tagged

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