COMP 141 Spring 2014

Program 2: Vending Machine

50 Points

Assigned: Friday, January 24
Due: Thursday, January 30, 2014 by 11:55pm

Description

Vending machines on campus sell lots of goodies for nominal fees. Assume that all snacks cost between 25 cents and 1 dollar, and prices are always multiples of 5. A user can only buy 1 item at a time, and the machine only accepts a single dollar bill for each transaction. You need to determine the correct change to be dispensed. You'll need to prompt the buyer for the price of their item and then determine their change in terms of # of quarters, # of dimes and # of nickels. Very few people prefer to get all nickels as their change, so be sure to always calculate quarters, then dimes, then nickels.

You should also make sure that your output is grammatically correct, such that if only 1 nickel is owed, then you output nickel rather than nickels. This program is meant to test your understanding of input statements, output statements, if-else statements, and mathematical calculations. It is not meant to test your understanding of functions; there will be other programs later to test your function skills.

What you need to do

Write a Python program that includes a main function. You are not required to write any other functions, but you must define a main function and call it. Your main function should:

Sample Interactions

Some examples of possible dialog with the user might be (user input is in italics):

Test 1

Enter price of item (from 25 cents to $1, in 5-cent increments): 45 
You bought an item for 45 cents and gave me a dollar.
Your change is 2 quarters, 0 dimes, and 1 nickel.

Test 2

Enter price of item (from 25 cents to $1, in 5-cent increments): 65
You bought an item for 65 cents and gave me a dollar.
Your change is 1 quarter, 1 dime, and 0 nickels.
Your code does not need to follow this exact script, but all the mentioned functionality should work as shown.

HINT: I recommend having the user enter an integer for the amount of change, not a floating point number, e.g. 65 not 0.65. (This will prevent weird floating point errors from happening.)
Get your program to output the correct # of quarters, dimes and nickels first before worrying about proper grammar.

What to Do

  • Create a Python program named yourlastname_prg2.py
  • Include the standard program header at the top of your Python file.
  • Submit your Python file on Moodle under Program 2.
  • Requirements

    When I examine your program, it must satisfy the following requirements. The maximum point value for each requirement is shown in brackets.

  • [2] Your program file is named correctly.
  • [3] You must include the standard program header as a comment at the top of your program.
  • [5] You must write a main function; use of other functions is optional.
  • [5] You must prompt the user for the cost of their item.
  • [15] You must calculate and output the total amount of change in quarters, dimes and nickels.
  • [15] You must use if-else statements to ensure proper grammar when outputting the total amount of change in quarters, dimes and nickels.
  • [5] You must comment your code appropriately and your code must be neatly and clearly formatted and include proper use of 'white space'.

  • Note: If your program doesn't run (i.e, has a syntax error), you may receive partial credit for the items listed above in bold.