Python Python program help with my math code

Click For Summary
The discussion centers around creating a Python program to calculate student loan payments and generate a detailed breakdown of each payment. The user has successfully developed a function to calculate the payment amount based on the principal, interest rate, number of payments, and payment frequency. However, they seek assistance in expanding their code to produce a table or list that includes the payment number, remaining balance, interest amount, and principal amount for each payment until the loan is paid off. The user emphasizes their beginner status in Python and their intention to use the program for a class presentation. The conversation invites suggestions on how to implement this feature effectively.
Juliayaho
Messages
13
Reaction score
0
Hi I built this code that runs well. Is about calculating a student loan... The problem is that I wish I could create a table that will tell me in each column "payment number", "remaining balance", "interest amount", "principal amount" Can you help me do this? I am new to python and this is not for a python class... I am just trying to build a math model and I thought that since python is a free program and I have used it once before... that I could use it again during my presentation in class.

Does anyone know how I can accomplish this?
Or it doesn't even have to be a table maybe a list of all the payments broken down till is paid off...
This is my code so far.

Code:

Code:
def calcDebt (principal, interestRate, numPayments, freqPayment):
    #This code will make different predictions to pay off student loan
    #Input Meanings
    '''
    Inputs
    - interestRate  - The Interest Rate of a Loan
    - numPayments - The Number of Payments Needed
    - principal - The Original Student Loan Amount
    - freqPayment - Frequency of Payments Based on Weekly, Monthly, Annually
    - m - The Minimum Payment Rate of Student Loan
    Returns
    - paymentAmount - The Payment Amount Will Be
    - minimumPayment - The Least Amount Needed to Pay
    '''

    freqPayment_lookup = {'weekly': 52, 'monthly':12, 'annually':1}
    interestRate = float(interestRate) / 100

    x = interestRate/freqPayment_lookup[freqPayment]
    y = (1.0 + x) ** numPayments
    z = x/(y - 1.0)
    paymentAmount = (x + z) * principal

    return paymentAmount
def main():
    a = input('Student Loan Amount: ')
    i = input('Student Loan Interest Rate: ')
    n = input('Number of Payments: ')
    f = None
    while f not in ['weekly', 'monthly', 'annually']:
        if f:
            f = raw_input('Sorry! That is NOT an Option. Please Enter weekly, monthly, or annually: ').lower()
        else:
            f = raw_input('How Often Do You Want To Make Your Payments? ').lower()
            m = input('Do You Know Your Minimum Payment Rate? If So, That is: ')
    payment = calcDebt(a, i, n, f)
    print 'Your %s payment will be %.2f' % (f, payment)
    minimumPayment = a * m / 100
    minToInterest = round((i/100)/12 *a)
    minToPrincipal = round(minimumPayment - (i/100)/12 * a)
    print 'You Must Pay ATLEAST the Minimum of:', minimumPayment
    print 'IF Only Minimum is Paid, This Amount Goes to Interest:', minToInterest
    print 'IF Only Minimum is Paid, This Amount Goes to Principal:', minToPrincipal
if __name__ == '__main__':
    main()
    raw_input('Please Press Enter to Exit')
 
Last edited:
Technology news on Phys.org
Juliayaho said:
Hi I built this code that runs well. Is about calculating a student loan... The problem is that I wish I could create a table that will tell me in each column "payment number", "remaining balance", "interest amount", "principal amount" Can you help me do this? I am new to python and this is not for a python class... I am just trying to build a math model and I thought that since python is a free program and I have used it once before... that I could use it again during my presentation in class.

Does anyone know how I can accomplish this?

This is my code so far.

Code:
def calcDebt (principal, interestRate, numPayments, freqPayment):
#This code will make different predictions to pay off student loan
#Input Meanings
'''
Inputs
- interestRate - The Interest Rate of a Loan
- numPayments - The Number of Payments Needed
- principal - The Original Student Loan Amount
- freqPayment - Frequency of Payments Based on Weekly, Monthly, Annually
- m - The Minimum Payment Rate of Student Loan
Returns
- paymentAmount - The Payment Amount Will Be
- minimumPayment - The Least Amount Needed to Pay
'''

freqPayment_lookup = {'weekly': 52, 'monthly':12, 'annually':1}
interestRate = float(interestRate) / 100

x = interestRate/freqPayment_lookup[freqPaym…
y = (1.0 + x) ** numPayments
z = x/(y - 1.0)
paymentAmount = (x + z) * principal

return paymentAmount
def main():
a = input('Student Loan Amount: ')
i = input('Student Loan Interest Rate: ')
n = input('Number of Payments: ')
f = None
while f not in ['weekly', 'monthly', 'annually']:
if f:
f = raw_input('Sorry! That is NOT an Option. Please Enter weekly, monthly, or annually: ').lower()
else:
f = raw_input('How Often Do You Want To Make Your Payments? ').lower()
m = input('Do You Know Your Minimum Payment Rate? If So, That is: ')
payment = calcDebt(a, i, n, f)
print 'Your %s payment will be %.2f' % (f, payment)
minimumPayment = a * m / 100
minToInterest = round((i/100)/12 *a)
minToPrincipal = round(minimumPayment - (i/100)/12 * a)
print 'You Must Pay ATLEAST the Minimum of:', minimumPayment
print 'IF Only Minimum is Paid, This Amount Goes to Interest:', minToInterest
print 'IF Only Minimum is Paid, This Amount Goes to Principal:', minToPrincipal
if __name__ == '__main__':
main()
raw_input('Please Press Enter to Exit')

Put your code between [code] [/code] tags, then the indentation will be preserved (which is quite imprtant since this is Python).

.
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 5 ·
Replies
5
Views
3K
Replies
10
Views
4K