Difference between revisions of "CSC111 Homework 2 2014"

From dftwiki3
Jump to: navigation, search
(Problem #3)
(Problem #1)
Line 31: Line 31:
 
  |  1  cent(s)                        |    
 
  |  1  cent(s)                        |    
 
  +------------------------------------+
 
  +------------------------------------+
 +
 +
It is totally acceptable to assume that the amount of money will never be more than $9,999.99, and therefore you can assume that the width of the box is constant and will always be large enough to accommodate an amount as large as $9999.99.
  
 
* Make sure your program contains a header.  The header is at the very top of the program, and is made of several comment lines.
 
* Make sure your program contains a header.  The header is at the very top of the program, and is made of several comment lines.
Line 40: Line 42:
  
 
<br />
 
<br />
 +
 
=Problem #2=
 
=Problem #2=
  

Revision as of 16:21, 5 February 2014

--D. Thiebaut (talk) 19:41, 4 February 2014 (EST)


You must work in Pair-Programming mode on this homework. This homework is due on Thursday evening, 2/13/14 at midnight.



Problem #1

  • Call your program hw2a.py
  • Using the same approach as took in Lab 2, write a Python program that asks the user for an amount of money (dollars) that can include cents, and outputs a breakdown of this amount into bills and coins.
  • This time, however, you must use the string-formatting output provided by the % operator, as introduced in Section 2.5.3 of the textbook. You cannot use the concatenation method we used to print your output. You must use the %-operator.

Here is an example of the output your program you emulate. Note the the line between the bills and the coins.

Please enter the amount of money you want to withdraw:  200.56

+------------------------------------+
| Total amount withdrawn:  $ 200.56  |
|                                    |
| 10  $20-bill(s)                    |
|  0  $10-bill(s)                    |
|  0  $5-bill(s)                     |
|  0  $1-bill(s)                     |
|-------------------                 |
|  3  quarter(s)                     |
|  0  dime(s)                        |
|  0  nickel(s)                      |
|  1  cent(s)                        |    
+------------------------------------+

It is totally acceptable to assume that the amount of money will never be more than $9,999.99, and therefore you can assume that the width of the box is constant and will always be large enough to accommodate an amount as large as $9999.99.

  • Make sure your program contains a header. The header is at the very top of the program, and is made of several comment lines.

In it you want to find the following information:

    • the name of the program
    • the name of the programmer(s), along with the 2-letter Id we'll use for this class.
    • the date the program was written
    • a description of what the program computes. What inputs it expects. Whether it will run for all possible inputs or if there are known cases for which it might not run.


Problem #2

Write a program call hw2b.py that will compute the total balance of an investment growing at a fixed yearly interest rate. The program should ask the user for two numbers:

  • A initial investment, entered as a real number ( 100, 2500.50, for example)
  • An interest rate, expressed as a real number less than 1. For example a 5% rate would be entered by the user as 0.05.

Your program will then output 10 lines representing the total balance of the investment after 1, 2, 3, ... 10 years.

We will forget that we have seen loops (the first week was just a quick exploration of Python and logic), so you will need 10 separate print statements to output the 10 balances.

Below is an example of how your program should operate. The user enters 1000 and 0.045 as the two inputs. The program outputs the rest.

Please enter the initial balance                  : 1000
Please enter the interest rate (enter 0.03 for 3%): 0.045

Table for an investment of $1000.00 at a rate of 4.5%
Balance after 1 year:   $1045.00
Balance after 2 year:   $1092.02
Balance after 3 year:   $1141.17
Balance after 4 year:   $1192.52
Balance after 5 year:   $1246.18
Balance after 6 year:   $1302.26
Balance after 7 year:   $1360.86
Balance after 8 year:   $1422.10
Balance after 9 year:   $1486.10
Balance after 10 years: $1552.97

Submit your program using the same link you used for Program 1.



Problem #3



Page under construction!
UnderConstruction.jpg