class HotelRoomCalc(object): 'Hotel room rate calculator' def __init__(self, rt, sales = 0.085, rm = 0.1): '''HotelRoomCalc default arguements: sales tax == 8.5% and room tax == 10% ''' self.salesTax = sales self.roomTax = rm self.roomRate = rt def calcTotal(self, days =1): 'Calcultate total; default to daily rate' daily = round((self.roomRate * (1 + self.roomTax + self.salesTax)), 2) return float(days) * daily sfo = HotelRoomCalc(299)print 'Instance San Francisco'print 'Daily rate $', sfo.calcTotal()print '2-day rate $', sfo.calcTotal(2)sea = HotelRoomCalc(189, 0.086, 0.058)print '\nInstance Seattle'print 'Daily rate $', sea.calcTotal()print '2-day rate $', sea.calcTotal(4)wasWkDay = HotelRoomCalc(169, 0.045, 0.02)wasWkEnd = HotelRoomCalc(119, 0.045, 0.02)print '\nWashington, D.C. 'print '$', wasWkDay.calcTotal(5) + wasWkEnd.calcTotal()
Running result
Instance San FranciscoDaily rate $ 354.312-day rate $ 708.62Instance SeattleDaily rate $ 216.222-day rate $ 864.88Washington, D.C. $ 1026.63