Explore BrainMass

Explore BrainMass

    Implement a simple mortgage calculator in Python.

    Not what you're looking for? Search our solutions OR ask your own Custom question.

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Implement a simple mortgage calculator in Python that calculates monthly mortgage payment amount such that each monthly payment repays same amount of principle, and monthly interest.

    When run, the program should display five menu options to perform mortgage related calculations and sixth option to exit the program, as indicated below.

    1. Monthly payment
    2. Total interest
    3. Monthly interest payment
    4. Principle left after monthly payment
    5. Daily payment rate for 30 days
    6. Exit the program

    All of the menu items perform different calculations and display result successfully.
    Program should continue asking user for a choice and performing relevant calculations, till user chooses to exit the program.

    © BrainMass Inc. brainmass.com October 4, 2022, 4:21 pm ad1c9bdddf
    https://brainmass.com/computer-science/python/implement-simple-mortgage-calculator-python-624099

    SOLUTION This solution is FREE courtesy of BrainMass!

    You can execute the attached program as "python 624099.py", or you can follow given steps to execute it like "./624099.py".
    - chmod +x 624099.py
    - Ensure that first "#!" line specifies correct path to Python interpreter on your system.
    ----------------------------------------------------
    #! /usr/bin/python

    #
    # This program implements a simple Mortgage Calculator for the user.
    # It is considered that each monthly payment repays same amount of
    # principle, and interest, irrespective of whether it is first month
    # payment or last month payment.
    #

    # This function presents user with 6 choices, and returns a valid
    # choice made by user.

    def menu ():
    menuString = """
    Simple Mortgage Calculator
    --------------------------
    1. Monthly payment
    2. Total interest
    3. Monthly interest payment
    4. Principle left after monthly payment
    5. Daily payment rate for 30 days
    6. Exit the program
    """

    print(menuString)
    choice = int(input("Please choose an option: "))

    # Accept only a valid choice
    while (choice < 1 or choice > 6):
    print("Invalid Choice!!")
    print(menuString)
    choice = int(input("Please choose an option: "))
    else:
    return choice

    # Following functions perform the necessary calculations as indicated by the
    # function name, and return the computed result.

    def monthly_mortgage_payment (principleAmt, termInMonths, annualIR):
    return (principleAmt*(annualIR/1200) /
    (1 - (1+annualIR/1200)**(-termInMonths)) )

    def total_interest_amount (principleAmt, termInMonths, annualIR):
    return (termInMonths
    * monthly_mortgage_payment(principleAmt,termInMonths,annualIR)
    - principleAmt)

    def monthly_interest_payment (principleAmt, termInMonths, annualIR):
    return (monthly_mortgage_payment(principleAmt,termInMonths,annualIR)
    - principleAmt/termInMonths)

    def principle_after_monthly_payment (principleAmt, termInMonths, annualIR):
    return (principleAmt -
    (monthly_mortgage_payment(principleAmt,termInMonths,annualIR)
    - monthly_interest_payment(principleAmt,termInMonths,annualIR)))

    def daily_mortgage_payment (principleAmt, termInMonths, annualIR):
    return monthly_mortgage_payment(principleAmt,termInMonths,annualIR)/30

    # This function performs necessary calculations as per user choice, and outputs
    # the results with appropriate message.
    # Choice will always be a valid value (1-5) when this function is called.

    def process_user_choice (choice, principleAmt, termInMonths, annualIR):

    if choice == 1:
    print "Your Monthly Payment of Mortgage would be ", monthly_mortgage_payment (principleAmt, termInMonths, annualIR)

    elif choice == 2:
    print "Your Total Interest Amount would be ", total_interest_amount (principleAmt, termInMonths, annualIR)

    elif choice == 3:
    print "Your Monthly interest Payment would be ", monthly_interest_payment (principleAmt, termInMonths, annualIR)

    elif choice == 4:
    print "Your Principle after monthly payment would be ", principle_after_monthly_payment (principleAmt, termInMonths, annualIR)

    else:
    # Since choice argument is a value in the range [1,5], reaching here means
    # user choice was 5.
    print "Your Daily Payment would be", daily_mortgage_payment (principleAmt, termInMonths, annualIR)

    # Main program logic begins here.
    # Repeatedly present user with menu and get a valid choice, and display the
    # result of asked-for calculations, till user wishes to exit the program.

    choice = menu()
    while choice < 6:
    # Get necessary information for calculation from the user.
    principleAmt = float(input("Please enter the principle amount: "))
    termInMonths = float(input("Please enter the mortgage term in months: "))
    annualIR = float(input("Please enter annual interest rate: "))

    # Perform the calculations as per user choice.
    process_user_choice(choice, principleAmt, termInMonths, annualIR)

    # Prompt the user to return to the main menu.
    raw_input("nPress any key to return to the main menu...")

    # Get next choice from the user.
    choice = menu()

    else:
    # Notify the user that the program is ending.
    print("Thanks for using Simple Mortgage Calculator!")

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    © BrainMass Inc. brainmass.com October 4, 2022, 4:21 pm ad1c9bdddf>
    https://brainmass.com/computer-science/python/implement-simple-mortgage-calculator-python-624099

    Attachments

    ADVERTISEMENT