Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
April 19th, 2013, 10:29 PM
 johncoleman12
Registered User

Join Date: Apr 2013
Posts: 1
Time spent in forums: 41 m 42 sec
Reputation Power: 0
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
April 20th, 2013, 11:57 AM
 b49P23TIvg
Contributing User

Join Date: Aug 2011
Posts: 4,168
Time spent in forums: 1 Month 3 Weeks 2 Days 9 h 55 m 17 sec
Reputation Power: 455
spoiler

Code:
```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!

 Viewing: Dev Shed Forums > Programming Languages > Python Programming > Coffee shop in IDLE help