Problem in Python [REPEATS AND DOES NOT GIVE THE NAME OF THE DETAIL]

0

I have a problem in Python which is the one above, I tell you what the program is about, the user enters a word in this case "MARKET" and gives a value of "10000" is repeated in the following, but when the detail is shown, two or intermediate of the two are repeated and it does not show the name [SEE RED PICTURE IMAGE], since 1 week ago I have this problem and I have not been able to solve it, I need the help to solve this, they are grateful .

The code is:

arregloDeGastos = []
gastos = []
sumaTotal = 0
nombreGasto = {}
salir = ("")
variable = 0


def detalles():
    sumaTotal = 0
    for i in range(len(arregloDeGastos)):
        print("Sus gastos en detalle fueron:" , arregloDeGastos[i])
        sumaTotal += arregloDeGastos[i]     
    print("Sus gastos totales fueron: ", sumaTotal)
    print()
    salario = int(input("Ingresa tu salario: "))
    sumaTotal = salario - sumaTotal
    print("Lo que te queda libre es,", sumaTotal,"Recuerda ahorrar.")
    return sumaTotal

while salir != "salir":
    print()
    salir = input("DALE ENTER PARA CONTINUAR, DE LO CONTRARIO salir: ")
    if(salir != "salir"):
        arregloDeGastos.append(int(variable))
        nombre = input("Digite el nombre del gasto: ")

        for j in range(1):
            print("Digite el valor del gasto",nombre,": ")
            gasto = int(input())
            arregloDeGastos.append(gasto)
            nombreGasto[nombre] = gastos

        gastos = []

        sumaTotal = 0

detalles()
    
asked by SAGC GC 04.05.2018 в 00:59
source

1 answer

1

Your problem is that you are adding to your array the value 0 when the user presses enter. In other words you are adding twice. The correct way would be to add only once after the user enters the expense like this:

while salir != "salir":
    print()
    salir = input("DALE ENTER PARA CONTINUAR, DE LO CONTRARIO salir: ")
    if(salir != "salir"):        
        nombre = input("Digite el nombre del gasto: ")

        for j in range(1):
            print("Digite el valor del gasto",nombre,": ")
            gasto = int(input())
            arregloDeGastos.append(gasto)
            nombreGasto[nombre] = gastos

        gastos = []

        sumaTotal = 0
    
answered by 04.05.2018 в 01:04