1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Rep Power

    Coffee shop in IDLE help

    I got very cocky thinking programming in IDLE would be similar to JAVA and I have no idea what I'm doing

    Can anyone help me out with the basic code structure of this problem

    Problem specification:
    Espresso is concentrated liquid coffee produced by passing steam through finely ground coffee
    beans. Some people enjoy drinking espresso straight, but others prefer a café latte, espresso in
    steamed milk; cappuccino, espresso in equal parts of steamed milk and milk foam; or
    Americano, espresso in near-boiling water. Espresso drinks are sold in three sizes: 8 oz., 12 oz.,
    and 16 oz. The base prices are shown in the price chart below. These drinks are made with a
    standard amount of espresso (1 shot), but coffee addicts often order additional shorts of
    espresso. The cost of an additional shot is $0.5 and is added to the base price of the drink. The
    tax of rate 0.088 is figured in to produce the final charge for the drink.

    Create a Python program to
    1. Allow the cashier to input the information needed for an order, and
    2. Print out the base price, the price including the extra shot(s), and the final price after tax
    for the customer.

    I have a table to work with but I'm not allowed to post links

    Any help would be greatly appreciated!
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Rep Power


    base_prices = dict(tax_rate = 0.088, shot = 0.50)
    base_prices[8] = 0.20
    base_prices[12] = 0.22
    base_prices[16] = 0.23
    def charge(size, shots=0):
            return dictionary of the charges
        result = dict(base_price = base_prices[size], extra_shots = base_prices['shot']*shots)
        result['subtotal'] = result['base_price'] + result['extra_shots']
        result['tax'] = result['subtotal'] * base_prices['tax_rate']
        result['total'] = result['subtotal'] + result['tax']
        return result
    def receipt(charges):
            given a dictionary of the charges, print a receipt.
        fmt = '{:>8s} ${:5.2f}'
        a = [fmt.format('Espresso', charges['base_price']),]
        es = charges['extra_shots']
        if es:
            a.append(fmt.format('shots', es))
        a.append(fmt.format('subtotal', charges['subtotal']))
        a.append(fmt.format('tax', charges['tax']))
        a.append(fmt.format('total', charges['total']))
        return '\n'.join(a)
    # example
    print(receipt(charge(12, 2)))
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo