Python program help with my math code

In summary,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.
  • #1
Juliayaho
13
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
  • #2
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).

.
 

Related to Python program help with my math code

1. What is Python and why is it useful for math programming?

Python is a high-level, interpreted programming language that is widely used for a variety of purposes, including math programming. It is useful for math programming because it has a simple syntax and a large library of mathematical functions, making it easy to write and execute complex mathematical operations.

2. How can I use Python to solve math problems?

Python has a built-in "math" library that contains functions for common mathematical operations such as addition, subtraction, multiplication, division, and more. You can also import other libraries, such as "numpy" or "scipy", for more advanced math operations like matrix manipulation or statistical analysis.

3. Can I use Python for graphing and visualization of mathematical data?

Yes, Python has several libraries, such as "matplotlib" and "seaborn", that allow you to easily create graphs and visualizations of your mathematical data. These libraries offer a wide range of customizable options for creating professional-looking plots.

4. How can I improve my math code in Python?

One way to improve your math code in Python is to use efficient algorithms and data structures. This can help optimize your code for speed and memory usage. Additionally, regularly reading and practicing with other people's code can help you learn new techniques and improve your skills.

5. Are there any online resources for learning Python for math programming?

Yes, there are many online resources available for learning Python for math programming, such as tutorials, courses, and forums. Some popular options include Codeacademy, Coursera, and Stack Overflow. You can also find numerous books and blogs that cover Python for math programming in-depth.

Similar threads

  • Programming and Computer Science
Replies
28
Views
2K
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
Replies
15
Views
1K
  • Programming and Computer Science
Replies
34
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
848
  • Programming and Computer Science
Replies
7
Views
4K
  • Programming and Computer Science
Replies
2
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
Back
Top