Skip to content Skip to sidebar Skip to footer

Assistance With Classes In This Python Program?

i have a program like this: To reserve hotel room according to user requirements. class Customer: def __init__(self,customer_id,customer_fname,customer_lname,customer_address

Solution 1:

classHotel(object):

    def__init__(self):
        self.header = ['Id', 'Room Type', 'Price', 'Units']
        self.hotel_room = {'1': {'name': 'KING DELUXE BEDROOM', 'price': 700, 'units': 7},
                           '2': {'name': 'QUEEN DUPLEX BEDROOM', 'price': 800, 'units': 8},
                           '3': {'name': 'CONTERMINOUS FAMILY SUITE', 'price': 1000, 'units': 10},
                           '4': {'name': 'GRAND TWIN PREMIER SUITE', 'price': 900, 'units': 9},
                           '5': {'name': 'TWOFOLD PENTHOUSE', 'price': 600, 'units': 6},
                           '6': {'name': 'LUXURIOUS POSH CABANA', 'price': 1300, 'units': 13},
                           '7': {'name': 'HEDONISTIC SPACIOUS LANAI', 'price': 650, 'units': 12}}

    defget_current_status(self):
        row_format = '{:>5}  {:<30}{:>10}{:>10}'print row_format.format(*self.header)
        for key in self.hotel_room:
            room = self.hotel_room[key]
            name = room['name']
            price = room['price']
            units = room['units']
            print row_format.format(key, name, price, units)

    defmake_reservation(self, room_type_id):
        if room_type_id in self.hotel_room:
            print"Making reservation of type : " + self.hotel_room[room_type_id]['name']
            self.hotel_room[room_type_id]['units'] -= 1print"Units left for : " + self.hotel_room[room_type_id]['name'] + " #" + \
                str(self.hotel_room[room_type_id]['units'])

hotel = Hotel()
hotel.get_current_status()
print"\nmaking a reservation for LUXURIOUS POSH CABANA\n"
hotel.make_reservation('6')
print"\ngetting current status\n"
hotel.get_current_status()

Output:

IdRoomTypePriceUnits1KINGDELUXEBEDROOM70073CONTERMINOUSFAMILYSUITE1000        102QUEENDUPLEXBEDROOM80085TWOFOLDPENTHOUSE60064GRANDTWINPREMIERSUITE90097HEDONISTICSPACIOUSLANAI650126LUXURIOUSPOSHCABANA1300        13makingareservationforLUXURIOUSPOSHCABANAMaking reservation of type :LUXURIOUSPOSHCABANAUnits left for :LUXURIOUSPOSHCABANA#12gettingcurrentstatusIdRoomTypePriceUnits1KINGDELUXEBEDROOM70073CONTERMINOUSFAMILYSUITE1000        102QUEENDUPLEXBEDROOM80085TWOFOLDPENTHOUSE60064GRANDTWINPREMIERSUITE90097HEDONISTICSPACIOUSLANAI650126LUXURIOUSPOSHCABANA1300        12

Solution 2:

print"ÏD\t\t\t:\t",self.customer_record['c_id']

This line contains a character that is not an ASCII character and you are using it as a string .I think that is causing the problem

Post a Comment for "Assistance With Classes In This Python Program?"