Department of Mathematics, Computer Science, and
                Statistics
St.
                Lawrence University
Zonohedron
 

What is this object?

...

Links
Overview
Schedule
Grading Info
Class Notes

 

CS 140: Introduction to Computer Programming


HOMEWORK #6
due Friday, Oct 26 by 5:00pm

Guidelines for completing and submitting homework
Refer to the first two paragraphs on the Grading Info page for all the details.  Briefly, you may not collaborate with your classmates while writing homework programs.  However, you may certainly consult Spencer on Thursday evenings or Dr. V on Friday afternoons as you create your programs.  (Email your program to me first to check that I'm in the office.)  Other QRC mentors may also be able to help out, depending on their experience with Python.  Once you have completed your program, or made as much progress as possible, email your program as an attachment to svandervelde@stlawu.edu.

Assignment
To begin, create a new document in Komodo and include these comments at the top
# Your full name
# Homework #6, Oct 26, 2012
# Individuals providing assistance, if any

Then save your file using the format LastnameHW6.py.

honda civic

Imagine that you have borrowed $28,000 to pay for a tricked out Honda Civic.  You plan to make monthly payments to repay the loan, which accumulates interest each month at the same time.  Your program this week will create a table illustrating how much money remains to be paid one year later based on the monthly interest rate and the amount of your payments.
  • Define a function called amount that takes two numerical arguments called rate and payment.  Within the function definition, first initialize remaining to equal 28000. Next use a for loop to go through all twelve months and repeatedly add on the interest to remaining, then subtract off  payment.  (You'll need to figure out how to determine the interest based on the given rate and the amount left. Note that the rate is a percentage, so you will need to divide by 100.0 somewhere.)
  • Now define a second function as
    def round(x):
         return int(x+.5)

    This function will round numbers to the nearest whole number.
  • Finally, create a table with six columns with monthly interest rates of 0.3, 0.4, 0.5, 0.6, 0.7, and 0.8 across the top.  Your table should have eleven rows corresponding to payments of 100, 110, 120, ..., 200 per month.  Use the above functions to compute the remaining balance in each case and display them nicely in the table.