Welcome to our community

Be a part of something great, join today!

[SOLVED] Python program help with my math code

Juliayaho

New member
Apr 11, 2013
13
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? Im new to python and this is not for a python class... Im 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:

zzephod

Well-known member
Feb 3, 2013
134
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? Im new to python and this is not for a python class... Im 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).

.