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

.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
I am trying to run an .ipynb file and have installed Miniconda as well as created an environment as such -conda create -n <env_name> python=3.7 ipykernel jupyter I am assuming this is successful as I can activate this environment via the anaconda prompt and following command -conda activate <env_name> Then I downloaded and installed VS code and I am trying to edit an .ipynb file. I want to select a kernel, via VS Code but when I press the button on the upper right corner I am greeted...

Similar threads

Back
Top