Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3623056
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T23:20:10+00:00 2026-05-18T23:20:10+00:00

The problem is to write the python that calculates the interest due on a

  • 0

The problem is to write the python that calculates the interest due on a loan and prints a payment schedule. The interest due on a loan can be calculated according to the simple formula:

I = P × R × T

where I is the interest paid, P is the amount borrowed (principal), R is the interest rate, and T is the length of the loan.

Finally it needs to displayed as follows:

The program will print the amount borrowed, total interest paid, the amount of the monthly payment, and a payment schedule.

Sample session

Loan calculator

Amount borrowed: 100
Interest rate: 6
Term (years): 1

Amount borrowed:    $100.00
Total interest paid:  $6.00

           Amount     Remaining
Pymt#       Paid       Balance
-----      -------    ---------
  0        $ 0.00      $106.00
  1        $ 8.84      $ 97.16
  2        $ 8.84      $ 88.32
  3        $ 8.84      $ 79.48
  4        $ 8.84      $ 70.64
  5        $ 8.84      $ 61.80
  6        $ 8.84      $ 52.96
  7        $ 8.84      $ 44.12
  8        $ 8.84      $ 35.28
  9        $ 8.84      $ 26.44
 10        $ 8.84      $ 17.60
 11        $ 8.84      $  8.76
 12        $ 8.76      $  0.00

The complete problem description is here: http://openbookproject.net/pybiblio/practice/wilson/loan.php
To accomplish this I have written the code which is as follows:

import decimal
from decimal import *
class loan_calc:

 def __init__(self):
  decimal.getcontext().prec = 3
  p = Decimal(input('Please enter your loan amount:'))
  r = Decimal(input('Please enter the rate of interest:'))
  t = Decimal(input('Please enter loan period:'))
  r_e = r/100
  i = p*r_e*t 
  term = t*12
  r_a = p+i
  amnt = p/term
  count = 0
  b_r = r_a
  print "Payment\t\tAmount Paid\t\tBal.Rem."
  while count <= term:
   if count == 0:
    print count,"\t\t"'0.00'"\t\t\t",b_r
    count += 1
    b_r -= amnt
    continue

   if term - count == 1:
    amnt = b_r
    print count,"\t\t",amnt,"\t\t\t",b_r
    count += 1
    b_r -= amnt
    continue

   else: 
    print count,"\t\t",amnt,"\t\t\t",b_r
    b_r -= amnt
    count += 1
    continue



loan = loan_calc()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T23:20:10+00:00Added an answer on May 18, 2026 at 11:20 pm

    Here’s an answer closely patterned to the way yours is written. Using the method I explained and suggested when you asked about how to round off a floating number in python, it uses the decimal module equivalent of the math module’s ceil function to get the same answer as shown at the practice link (except for some minor output formatting). I also re-indented the code to the more commonly used 4-spaces, and renamed the variables to be a little more readable. Hope you learn something from it. Notice that I don’t set decimal.getcontext().prec to 3 (I don’t believe it does what you think).

    import decimal
    
    def main():
        principle = decimal.Decimal(raw_input('Please enter your loan amount:'))
        rate = decimal.Decimal(raw_input('Please enter rate of interest (percent):')) / 100
        term = decimal.Decimal(raw_input('Please enter loan period (years):')) * 12
    
        interest = (principle * rate).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_HALF_EVEN)
        balance = principle + interest
        payment = (balance / term).quantize(decimal.Decimal('.01'), rounding=decimal.ROUND_CEILING)
        print "Payment\t\tAmount Paid\t\tRem.Bal."
        for count in range(1+term):
            if count == 0:
                print count, "\t\t0.00\t\t\t", balance
            elif count == term: # last payment?
                payment = balance
                balance -= payment
                print count, "\t\t", payment, "\t\t\t", balance
            else:
                balance -= payment
                print count, "\t\t", payment, "\t\t\t", balance
    
    main()
    
    # > python loan_calc.py
    # Please enter your loan amount:100
    # Please enter rate of interest (percent):6
    # Please enter loan period (years):1
    # Payment         Amount Paid             Rem.Bal.
    # 0               0.00                    106.00
    # 1               8.84                    97.16
    # 2               8.84                    88.32
    # 3               8.84                    79.48
    # 4               8.84                    70.64
    # 5               8.84                    61.80
    # 6               8.84                    52.96
    # 7               8.84                    44.12
    # 8               8.84                    35.28
    # 9               8.84                    26.44
    # 10              8.84                    17.60
    # 11              8.84                    8.76
    # 12              8.76                    0.00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a Python program that makes PNG files. My big problem
Here is my problem. I am trying to write a small simple game engine
I have problem with fancybox. I want to write a function that will run
When I write a C program, I encountered a problem that is as follows:
I'm currently trying to write a multiple-file Python (2.6.5) game using PyGame. The problem
I'm trying to write a python script that does the following from within a
When you want to write a query in Python that will select (from SQLite
I can't run firefox from a sudoed python script that drops privileges to normal
I'm trying to write a python script that packages our software. This script needs
I'm trying to write a python script that modifies the contents of <script> tag

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.