Computer Sciences 303e - Programming Assignment 2


Covered topics:
Printing with the print function, and formatting output using tabs
Arithmetic operations with % and / (integer division)
Explicit casts
input() function

Note: You are not allowed to use any looping or conditional structures in this program, or any programming constructs that have not been covered in class.


Write a program that asks the user to enter some amount of money and prints out exact change. Your change should involve the fewest possible number of coins, i.e. for $.25, the change should consist of one quarter, not two dimes and one nickel.

Floating-point operations (arithmetic operations with values of type float) can result in round-off error. You need to make sure that you do not lose precision in the number of cents in your dollar amount.

Hint:
Try multiplying the money amount by 100, then rounding to the nearest integer (with the round function) and casting this value to type int to get the number of cents.

For example:
cents = int(round(money*100))


Sample Run:



Your program should:

  • be contained in a file called Money.py.
  • have the following header at the top of your program:

    # File: Money.py
    # Description: --a description of your program--
    #
    # Name: --your name--
    # EID: --your eid--
    # Course Name: CS 303e
    #
    # Unique Number: --your section number--
    #
    # Date created:
    # Date last modified:
    #
    # Slip days used this assignment:
    # Total slip days used:
    #

  • Your program should:
  • contain and call a main function
  • use tabs to line up the number of dollars, quarters, etc. in your output
  • make use of meaningingful variable names
  • use comments to document your program
  • use whitespace and indentation to enhance readability
  • use the tab escape sequence


  • For input value 15.34, your output should look exactly like the sample output above. You will lose credit if it does not. Test your program on at least 5 different money amounts, including 15.34, 0.27, and 1.83.

    Programs that do not compile will not receive any credit. Please plan ahead and allow plenty of time to get help from the TAs, proctors or instructor if you are having trouble with the program. Please do not email the course staff the day before the assignment is due if you need help - it is unlikely that we will respond quickly enough to assist you. Plan to come to the lab during office hours if you need help.


    This program must be submitted by 11 pm on the due date in order to be considered on time. Please note in your program header how many slip days you used on this project. If you use slip days, you must email Al and Jordan when you submit your project. The email subject should be: "cs 303e: lab 2, late submission".  If you do not notify Al and Jordan, your project will not be graded, so this is important.

    This project must be done individually. You may talk to your classmates about solution approaches, but then you must write your own code.


    Reminders - Did you remember to:
        do this assignment by yourself?
        include comments for readability?
        make sure that your program does not produce an error?
        make sure that your output matches the sample output above?
        submit your program in file Money.py using the turnin program by 11 pm on the due date?