How to print the balance in ascending order and calculate interest in python

0

Personal I have a job in which I should reproduce the following table: IdonothavemuchknowledgeinpythonandI'mdoingmybesttotrytoreproduceit.ButI'monlyabletoreturnthisway. Mydoubtsareasfollows:

  • ThemonthIdonotknowhowtoputinascendingorderorremovethe0intheend.
  • FromthestartbalancetothefinalbalanceIcanprint,theproblemisthatitprintsto0.
  • Idonotknowthelogicoftheprovision.
  • IdonotknowthelogicofInterest(greenboard).
  • Idonotknowthelogicofmonthlyinterest(redframe).
  • Idonotknowhowtoprintthefinalbalance(whichinthiscaseistheopeningbalance).
  • Hereismycodebelow:

    #enconding:utf-8#########################################VERSÃOUTILIZADA:Python3.6.5##DISCIPLINA:IntroduçãoàProgramação###################################################################################Informaçõesdeentradadadapelouser##########################################importosvalor_financiamento=float(input("1. Informe o valor a ser financiado: "))
    os.system("cls")
    prazo = int ( input ("2. Informe o prazo de quitação do financiamento (em meses): "))
    os.system("cls")
    taxa_juros_anual = float (input ("3. Informe a taxa de juros anual (em %): "))
    os.system("cls")
    
    
    # Início da programação e cálculo
    # USO DO SISTEMA SAC       
    
    
    # O cálculo da amortização é realizado pelo valor do financiamento divido pela quantidade de meses
    amortizacao = valor_financiamento / prazo
    
    saldo_devedor = valor_financiamento - amortizacao
    
    taxa_mensal = taxa_juros_anual / prazo
    
    juros_mes = (taxa_juros_anual - 1 + 1 ) * amortizacao * taxa_mensal
    
    prestacao = amortizacao + juros_mes
    #valor_financiamento = str (valor_financiamento).replace('.',',')
    
    
    #print ("AMORTIZAÇÃO: R$ %.2f" % amortizacao)
    #print ("VALOR DO FINANCIAMENTO: R$ %.2f\n\n" % valor_financiamento)
    print ("\t FINANCIAMENTO = R$ %.2f \t MESES: %i meses \t TAXA: %i%% ano (%.f%)" % (valor_financiamento, prazo, taxa_juros_anual, juros_mes))
    print ("\t","-"*80,"\n")
    print ("\t MÊS\tSALDO INICIAL\tPRESTAÇÃO\tAMORTIZAÇÃO\tJUROS\tSALDO FINAL")
    print ("\t ---\t-------------\t---------\t-----------\t-----\t-----------")
    
    print ("\t%4.i \t %12.2f \t\t\t %10.2f" % (prazo, valor_financiamento, amortizacao))
    for p in range(prazo):
        while (valor_financiamento > 1):
            valor_financiamento = valor_financiamento - amortizacao # Saldo devedor
            prazo = prazo - 1 # Referência do mês
            saldo_devedor = valor_financiamento - amortizacao
            saldo_final = saldo_devedor - amortizacao
            print ("\t%4.i \t %12.2f \t\t\t %10.2f" % (prazo, valor_financiamento, amortizacao)) #% valor_financiamento)
            #print (prazo)
    

    This issue is a matter of real estate financing under the SAC system:

    Question

    Construct a program that generates a table of the monthly installments of a loan, detailing the amortization and interest payments to be paid up to the full amortization of the financing. This program should present a menu of options and ask the following information to the user: Amount financed, Term (in months) for discharge of the financing, Annual interest rate (in percentage) and Systematic monthly payment of installments (Constant Amortization System - SAC or PRICE system - see attached explanatory note). Additional features are welcome!

    The amount of a loan must be repaid (amortized) to the lender within a certain period of time, plus interest. Amortizing means reducing the value of the debt, that is, paying a portion of the debt periodically so that it reduces in size until its elimination. As the debt implies interest collection, to repay it it is necessary that the benefit be greater than the interest charged in each period, that is, AMORTIZATION = PAYMENT - INTEREST (the amortized amount is what is left over after discounting the interest) . Interest only levied on the debit balance, where DEBT BALANCE = INITIAL DEBT - AMORTIZED AMOUNT. The ways to amortize financing are called "Amortization Systems".

    Constant Amortization System (SAC): In this system, the balance due is repaid periodically in equal amortization amounts. In this way, the value of benefits is decreasing, since interest rates decrease for each benefit. The amortization value is calculated by dividing the principal amount (value of the financing) by the number of payment periods, that is, of installments. Thus,

     Amount of amortization: AMORTIZATION = MAIN / N

    • Interest rate in month T: JUROST = (N - T + 1) * AMORTIZATION * RATE

     Value of the portion in T: PERFORMANCE = AMORTIZATION + JUROST

    where: PRINCIPAL is the amount of the financing, N is the number of months of the financing, T denotes the month in question and RATE is the monthly interest rate (which must be obtained from the annual rate).

    If someone can help me at least with logic. It's a great start.

        
    asked by anonymous 20.06.2018 / 23:07

    1 answer

    1

    Read the statement of your own problem, doing the very great favor,

    import os
    
    principal = float ( input ("1. Informe o valor a ser financiado: "))
    os.system("cls")
    n = int ( input ("2. Informe o prazo de quitação do financiamento (em meses): "))
    os.system("cls")
    taxa_juros_anual = float (input ("3. Informe a taxa de juros anual (em %): ")) / 100.0
    os.system("cls")
    
      

    Amount of amortization: AMORTIZATION = MAIN / N

    amortizacao = principal / n
    

    A search for monthly rate from the compound annual interest rate on Google returns the following formula,

      

    1 + ANNUAL RATE = (1 + MONTHLY RATE) ^ 12 Source: here

    taxa_juros_mensal = pow(1.0 + taxa_juros_anual, 1.0 / 12) - 1.0;
    
    print ("AMORTIZAÇÃO: R$ %.2f" % amortizacao)
    print ("VALOR DO FINANCIAMENTO: R$ %.2f\n\n" % principal)
    print ("\t FINANCIAMENTO = R$ %.2f \t MESES: %i meses \t TAXA: %i%% ano (%.f%%)" % 
        (principal, n, taxa_juros_anual, taxa_juros_mensal))
    print ("\t","-"*80,"\n")
    print ("\t MÊS\tSALDO INICIAL\tPRESTAÇÃO\tAMORTIZAÇÃO\t  JUROS\tSALDO FINAL")
    print ("\t ---\t-------------\t---------\t-----------\t-------\t-----------")
    
    saldo_inicial = principal
    for t in range(1, n + 1):
        saldo_final = saldo_inicial - amortizacao
        juros = juros_t(t, n, amortizacao, taxa_juros_mensal)
        prestacao = amortizacao + juros
    
        print ("\t%4.i\t%13.2f\t%9.2f\t%11.2f\t%7.2f\t%11.2f" % 
            (t, saldo_inicial, prestacao, amortizacao, juros, saldo_final))
        saldo_inicial = saldo_final
    
      

    Interest rate in month T: JUROST = (N - T + 1) * AMORTIZATION * RATE

    def juros_t(t, n, amortizacao, taxa):
          return (n - t + 1) * amortizacao * taxa
    
        
    21.06.2018 / 02:06