Class notes-book 344 page example 13.1 (hotel. py)-instantiate with default parameters with slight modifications

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.