Python Python program help with my math code

AI Thread 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).

.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Back
Top