2
I am having a small problem in my algorithm I have to receive a "name of an institution" any typed by the user and convertlist to use it in future other conditions but it is converting to string all the letters of the name and putting in a list thus being unable to use it as a new list declared by the "user" to use in other conditions.
instituicão = []
print("Digite o nome da instituição que deseja adicionar.\n 0 - Para
parar de adicionar\n")
while True:
instituicão_add = input("digite alguma instituicao")
#Supor que o usuário botou "ADD"
conversão_lista = list(instituicão_add)
#funcionaria se tivesse em str mas o print vai sair como dito
#ja para o input direto nao sei qual condição bota para parar
if instituicão_add == "0": #<<< ???
break
else:
instut.append(conv_list)
print(instituicão)
#Ai no caso meu print sai se tiver str(input("")) assim [['a', 'd', 'd']]
#O certo para min seria sair assim [["alguma coisa"]]
for indice,na_lista in enumerate(instituicão):
print(indice, "-", na_lista)
inst = int(input("\nQual instituição deseja escolher?"))
x = inst #recebendo o indice que seria pra entra na lista que desejasse
if inst == x:
dinheiro = int(input("\nQuanto deseja doar?\n")
instituicão[x].append(dinheiro)
print("Obrigado por ajudar esta instituição")
print(instituicão[x])
Here in this last "print" I wanted it to come out [["value of donated money"]], by the user within the institution added by it is transformed into a list that should return [["xxxxx"]], however I am not able to make this algorithm work so if you can help me.
Python3 lets you accentuate variables - but that doesn’t mean you should do it! : -) But if you’re going to do it, it’s important to maintain consistency: The variable should be
instituição
(orinstituicao
) - neverinstituicão
- how will you be able to remember where you used special names or not when the program is larger?– jsbueno
Alias- try using the same names for the same variable - having a "conversion_list" that you try to use a few lines below with the name "conv_list" will not help your program to work.
– jsbueno
hey how I keep the received value without overwriting the previous one because how and dicionario I am not getting saved as I do in normal lists, type if in the donation type 1000 and I want to donate again and type 20 should be saved 1020 and not overwrite for 20 and I have no idea how to do this in dictionary.
– Alysson Maia