Exercise 3

ex3.py
Fall 2012 MT1 (solutions)
Spring 2013 MT1 (solutions)

Q1. Create a class called VendingMachine that represents a vending machine for some product. A VendingMachine object doesn't actually return anything but strings describing its interactions. See the doctest below for examples.


				class VendingMachine(object):
				    """A vending machine that vends some product for some price.

				    >>> v = VendingMachine('crab', 10)
				    >>> v.vend()
				    'Machine is out of stock.'
				    >>> v.restock(2)
				    'Current crab stock: 2'
				    >>> v.vend()
				    'You must deposit $10 more.'
				    >>> v.deposit(7)
				    'Current balance: $7'
				    >>> v.vend()
				    'You must deposit $3 more.'
				    >>> v.deposit(5)
				    'Current balance: $12'
				    >>> v.vend()
				    'Here is your crab and $2 change.'
				    >>> v.deposit(10)
				    'Current balance: $10'
				    >>> v.vend()
				    'Here is your crab.'
				    >>> v.deposit(15)
				    'Machine is out of stock. Here is your $15.'
				    """
				    "*** YOUR CODE HERE ***"
			

Q2. Complete one of the midterms attached above.