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

Asked

Viewed 945 times

0

Personal I have a job in which I must reproduce the following table: inserir a descrição da imagem aqui I don’t have much knowledge in python and am doing my best to try to reproduce it. But I am managing to return only in this way. inserir a descrição da imagem aqui My doubts are as follows::

  1. The month I don’t know how to put in the ascending order and nor remove the 0 in the end.
  2. From the starting balance to the final balance I can print, the problem is that he prints up to 0.
  3. I don’t know the logic of the performance.
  4. I do not know the logic of Interest (green framework).
  5. I do not know the logic of monthly interest (red table).
  6. I don’t know how to print the final balance (which in this case is the inverse of the opening balance).

Follow my code below:

# enconding: utf-8
########################################
# VERSÃO UTILIZADA: Python 3.6.5       #
# DISCIPLINA: Introdução à Programação #
########################################

#########################################
# Informações de entrada dada pelo user #
#########################################

import os

valor_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 question of real estate financing under the SAC system:

Question

Construct a program that manages a table with the monthly instalment values of a loan, detailing the amounts of amortization and interest to be paid until the total amortization of the financing. This program must present a menu of options and ask the following information to the user: Amount financed, Deadline (in months) for discharge of the financing, Annual interest rate (in percentage) and the Systematic monthly payment of benefits (Constant Amortisation System - SAC or PRICE System - see explanatory note attached). Additional features are welcome!

The value of a loan must be returned (amortised) to the lender in a certain period of time, plus interest. Amortizing means reducing the value of the debt, that is, paying off a portion of the debt periodically so that it reduces in size until its elimination. As the debt implies the collection of interest, to amortize it it is necessary that the installment is greater than the interest charged in each period, that is, AMORTIZATION = PAYMENT - INTEREST (the amortized value is what is left over after discounting the interest). The interest is only on the debit balance, where DEBIT BALANCE = INITIAL DEBT - AMORTISED VALUE. The forms of amortizing financing are called "Amortization Systems".

Constant Amortization System (SAC): In this system, the debit balance is periodically repaid in equal amortization values. In this way, the value of the instalments is decreasing, since the interest decreases with each instalment. The depreciation value is calculated by dividing the principal value (value of the financing) by the number of payment periods, ie by instalments. Thus,

Amortisation value: AMORTISATION = PRINCIPAL / N

Interest value in month T: JUROST = (N - T + 1) * AMORTISATION * RATE

Value of the plot in T: SERVICES = AMORTIZATION + JUROST

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

If anyone can help me at least with logic. It’s a great start.

1 answer

1


Read the statement of your own problem, doing the greatest 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")

Amortisation value: AMORTISATION = PRINCIPAL / N

amortizacao = principal / n

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

1 + ANNUAL FEE = (1 + MONTHLY FEE) 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 value in month T: JUROST = (N - T + 1) * AMORTISATION * RATE

def juros_t(t, n, amortizacao, taxa):
      return (n - t + 1) * amortizacao * taxa
  • Marcelo, first of all thank you very much for the help! I’m glad that at least I could understand the logic of the program right. Remembering that I am still beginner in programming and do not know much about python. Mainly the teacher passing difficult issues like this to beginner students like me solve. But from now on thank you very much! I could understand what I wasn’t getting.

Browser other questions tagged

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