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:

class Hotel(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}}

    def get_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)

    def make_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'] -= 1
            print "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:

   Id  Room Type                          Price     Units
    1  KING DELUXE BEDROOM                  700         7
    3  CONTERMINOUS FAMILY SUITE           1000        10
    2  QUEEN DUPLEX BEDROOM                 800         8
    5  TWOFOLD PENTHOUSE                    600         6
    4  GRAND TWIN PREMIER SUITE             900         9
    7  HEDONISTIC SPACIOUS LANAI            650        12
    6  LUXURIOUS POSH CABANA               1300        13

making a reservation for LUXURIOUS POSH CABANA

Making reservation of type : LUXURIOUS POSH CABANA
Units left for : LUXURIOUS POSH CABANA #12

getting current status

   Id  Room Type                          Price     Units
    1  KING DELUXE BEDROOM                  700         7
    3  CONTERMINOUS FAMILY SUITE           1000        10
    2  QUEEN DUPLEX BEDROOM                 800         8
    5  TWOFOLD PENTHOUSE                    600         6
    4  GRAND TWIN PREMIER SUITE             900         9
    7  HEDONISTIC SPACIOUS LANAI            650        12
    6  LUXURIOUS POSH CABANA               1300        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?"