0

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,customer_contactno,customer_noofdays):
                       self.customer_id=customer_id
                       self.customer_fname=customer_fname
                       self.customer_lname=customer_lname
                       self.customer_address=customer_address
                       self.customer_contactno=customer_contactno
                       self.cost=0
                       self.noofdays=customer_noofdays
                       self.reservation_id=[]
                       self.customer_record={'c_name':self.customer_fname+""+self.customer_lname,
                           'c_id':self.customer_id,
                           'c_wallet':self.cost,
                           'c_days':self.noofdays,
                           'c_reservation_id':self.reservation_id}
     def Total(self):
               print"\n"
               print"ÏD\t\t\t:\t",self.customer_record['c_id']
               print"Name\t\t\t:\t",self.customer_record['c_name']
               print"Amount to be paid\t:\t",self.customer_record['c_wallet']
               print"\n"
 class Reservation:
         def __init__(self):
               self.hotel_price={'KING DELUXE BEDROOM':700,
                      'QUEEN DUPLEX BEDROOM':800,
                      'CONTERMINOUS FAMILY SUITE':1000,
                      'GRAND TWIN PREMIER SUITE':900,
                      'TWOFOLD PENTHOUSE':600,
                      'LUXURIOUS POSH CABANA':1300,
                      'HEDONISTIC SPACIOUS LANAI':650}


               self.hotel_room={'KING DELUXE BEDROOM':7,
                      'QUEEN DUPLEX BEDROOM':8,
                      'CONTERMINOUS FAMILY SUITE':10,
                      'GRAND TWIN PREMIER SUITE':9,
                      'TWOFOLD PENTHOUSE':6,
                      'LUXURIOUS POSH CABANA':13,
                      'HEDONISTIC SPACIOUS LANAI':12}
        def currentstatus(self,option):
                   if(option=='Hotelroom'):
                         print"            THE FOLLOWING ROOMS ARE AVAILABLE FOR YOUR STAY"
                         print"    "
                         print"        ROOMS                   ROOMS AVAILABLE    "

                         print" 1.HEDONISTIC SPACIOUS LANAI        12    "                                  
                         print" 2.QUEEN DUPLEX BEDROOM              8    "   
                         print" 3.CONTERMINOUS FAMILY SUITE        10    "
                         print" 4.LUXURIOUS POSH CABANA            13    "                  
                         print" 5.TWOFOLD PENTHOUSE                 6    "
                         print" 6.GRAND TWIN PREMIER SUITE          9    "
                         print" 7.KING DELUXE BEDROOM               7    "
                         print""

                         for key,value in self.hotel_room.items():

                                     print key,value
                   elif(option=="Hotelprice"):
                               print"            THE FOLLOWING ROOMS ARE AVAILABLE FOR YOUR STAY"
                               print"    "
                               print"        ROOMS                       PRICE(RS)    "

                               print" 1.HEDONISTIC SPACIOUS LANAI        1200    "                                  
                               print" 2.QUEEN DUPLEX BEDROOM              800    "   
                               print" 3.CONTERMINOUS FAMILY SUITE        1000    "
                               print" 4.LUXURIOUS POSH CABANA            1300    "                   
                               print" 5.TWOFOLD PENTHOUSE                 600    "
                               print" 6.GRAND TWIN PREMIER SUITE          900   "
                               print" 7.KING DELUXE BEDROOM               700    "
                               print""


class Hotel(Reservation):
            def __init__(self,Reservation,Customer,hotel_room_selection,hotel_check_in_date,hotel_check_out_date,hotel_noof_days):
             self.hotel_room_selection=hotel_room_selection
             self.hotel_check_in_date=hotel_check_in_date
             self.hotel_check_out_date=hotel_check_out_date
             self.noofdays=noofdays

           def Checkavailability(self):
                    if reserve.hotel_room.get(self.hotel_room_selection)>0:
                            reserve.hotel_room[self.hotel_room_selection]-=1
                                                                Person.customer_record['c_wallet']+=reserve.hotel_price[self.hotel_room_selection]
                            print"\n\n HOTEL ROOM HAS BEEN RESERVED FOR YOUR STAY \n\n"
                   else:
                           print"SORRY! ROOMS ARE NOT AVAILABLE"
          def calculateprice(self):
                    if (Person.customer_record['c_days']==1):
                             Person.customer_record['c_wallet']=0.1*Person.customer_record['c_wallet']+Person.customer_record['c_wallet']
                    elif (Person.customer_record['c_days']==2):
              Person.customer_record['c_wallet']=0.3*Person.customer_record['c_wallet']+Person.customer_record['c_wallet']
                   elif(Person.customer_record['c_days']==3):
          Person.customer_record['c_wallet']=0.5*Person.customer_record['c_wallet']+Person.customer_record['c_wallet']
                   elif(Person.customer_record['c_days']==4):
          Person.customer_record['c_wallet']=0.7*Person.customer_record['c_wallet']+Person.customer_record['c_wallet']
                   else:
          Person.customer_record['c_wallet']=0.9*Person.customer_record['c_wallet']+Person.customer_record['c_wallet']


  reservation=1
  reserve=Reservation()
  CustomerID=1
  Hotelroom=['KING DELUXE BEDROOM',
                      'QUEEN DUPLEX BEDROOM',
                      'CONTERMINOUS FAMILY SUITE',
                      'GRAND TWIN PREMIER SUITE',
                      'TWOFOLD PENTHOUSE',
                      'LUXURIOUS POSH CABANA',
                      'HEDONISTIC SPACIOUS LANAI']

  while(reservation==1):
    print"Royal Palace welcomes you"
    fname=raw_input("ENTER YOUR FIRST NAME: ")
    lname=raw_input("ENTER YOUR SECOND NAME: ")
    address=raw_input("ENTER THE ADRESS: ")
    contactno=input("ENTER THE PHONE NUMBER: ")
    noofdays=input("ENTER THE NUMBER OF DAYS OF STAY: ") 
    Person=Customer(CustomerID,fname,lname,address,contactno,noofdays)
    print"\n"

    HotelReservationChoice=input("DO YOU WANT HOTEL FACILITY?? IF YES,PRESS 1: ")
    if(HotelReservationChoice==1):
                  print"\n"
                  HotelChoice=1
                  reserve.currentstatus('Hotelroom')
                  print"\n"
                  for room in Hotelroom:

                       HotelChoice+=1
                  print""
                  HotelFare=input("DO YOU WANT TO CHECK RATE OF ROOMS?? IF YES,PRESS 1: ")
                  print""
                  if(HotelFare==1):
                          reserve.currentstatus('Hotelprice')
                  print""
                  HChoice=input("ENTER YOUR CHOICE OF ROOM: ")
                  CheckOutDate=raw_input("ËNTER THE DATE OF CHECKOUT FROM THE HOTEL: ")
                  CheckInDate=raw_input("ËNTER DATE OF CHECK IN TO THE HOTEL: ")
                  noofdays=input("ËNTER THE NUMBER OF DAYS OF STAY: ")
                  H1=Hotel(reserve,Person,Hotelroom[HChoice-1],CheckOutDate,CheckInDate,noofdays)
                  H1.Checkavailability()
                  H1.calculateprice()
                  reserve.currentstatus('Hotelroom')
                  Person.Total()
  reservation=input("DO YOU WANT ANOTHER RESERVATION?? IF YES,PRESS 1:")
  print""
  CustomerID+=1

The output comes like:

    Royal Palace welcomes you
    ENTER YOUR FIRST NAME: qqq
    ENTER YOUR SECOND NAME: qqq
    ENTER THE ADRESS: qqq
    ENTER THE PHONE NUMBER: 111
    ENTER THE NUMBER OF DAYS OF STAY: 1


   DO YOU WANT HOTEL FACILITY?? IF YES,PRESS 1: 1


        THE FOLLOWING ROOMS ARE AVAILABLE FOR YOUR STAY

    ROOMS                   ROOMS AVAILABLE    
1.HEDONISTIC SPACIOUS LANAI        12    
2.QUEEN DUPLEX BEDROOM              8    
3.CONTERMINOUS FAMILY SUITE        10    
4.LUXURIOUS POSH CABANA            13    
5.TWOFOLD PENTHOUSE                 6    
6.GRAND TWIN PREMIER SUITE          9    
7.KING DELUXE BEDROOM               7    

# The following is room availability. i want it to display like the print   format given above,but not here but at the end. but my program executes in such a way that its also getting printed here like this.

HEDONISTIC SPACIOUS LANAI 12
QUEEN DUPLEX BEDROOM 8
CONTERMINOUS FAMILY SUITE 10
LUXURIOUS POSH CABANA 13
TWOFOLD PENTHOUSE 6
GRAND TWIN PREMIER SUITE 9
KING DELUXE BEDROOM 7



DO YOU WANT TO CHECK RATE OF ROOMS?? IF YES,PRESS 1: 1

        THE FOLLOWING ROOMS ARE AVAILABLE FOR YOUR STAY

    ROOMS                       PRICE(RS)    
1.HEDONISTIC SPACIOUS LANAI        1200    
2.QUEEN DUPLEX BEDROOM              800    
3.CONTERMINOUS FAMILY SUITE        1000    
4.LUXURIOUS POSH CABANA            1300    
5.TWOFOLD PENTHOUSE                 600    
6.GRAND TWIN PREMIER SUITE          900   
7.KING DELUXE BEDROOM               700    


ENTER YOUR CHOICE OF ROOM: 1
ËNTER THE DATE OF CHECKOUT FROM THE HOTEL: 11
ËNTER DATE OF CHECK IN TO THE HOTEL: 11
ËNTER THE NUMBER OF DAYS OF STAY: 1


HOTEL ROOM HAS BEEN RESERVED FOR YOUR STAY 


        THE FOLLOWING ROOMS ARE AVAILABLE FOR YOUR STAY

       ROOMS                   ROOMS AVAILABLE    
 1.HEDONISTIC SPACIOUS LANAI        12    
 2.QUEEN DUPLEX BEDROOM              8    
 3.CONTERMINOUS FAMILY SUITE        10    
 4.LUXURIOUS POSH CABANA            13    
 5.TWOFOLD PENTHOUSE                 6    
 6.GRAND TWIN PREMIER SUITE          9    
 7.KING DELUXE BEDROOM               7    

 # this is where i want the room availability to display after decreasing   the  number of rooms when one is reserved. but i want it to be in the above format and not haphazardly like this: 

 #1
 HEDONISTIC SPACIOUS LANAI 12
 QUEEN DUPLEX BEDROOM 8
 CONTERMINOUS FAMILY SUITE 10
 LUXURIOUS POSH CABANA 13
 TWOFOLD PENTHOUSE 6
 GRAND TWIN PREMIER SUITE 9
 KING DELUXE BEDROOM 6


 ÏD         :   1
 Name           :   qqqqqq
 Amount to be paid  :   770.0


 DO YOU WANT ANOTHER RESERVATION?? IF YES,PRESS 1:2

 >>> 

Can you help with the code so that it comes like

 #2.

 ROOMS                   ROOMS AVAILABLE    
 1.HEDONISTIC SPACIOUS LANAI        12    
 2.QUEEN DUPLEX BEDROOM              8    
 3.CONTERMINOUS FAMILY SUITE        10    
 4.LUXURIOUS POSH CABANA            13    
 5.TWOFOLD PENTHOUSE                 6    
 6.GRAND TWIN PREMIER SUITE          9    
 7.KING DELUXE BEDROOM               6(# the decrease can be shown and not  printing.)   

i tried many things, but i still it won't work.Could you take a look and tell me the problem??I spend too much time in this.(The indentation under if conditions are correct). Thankyou!

  • If you don't want tabs why are you adding them? – Padraic Cunningham Nov 14 '15 at 19:09
  • sorry,but i didn't understand. – vanikavaisya trust Nov 14 '15 at 19:14
  • I mean you want ROOMS left aligned but you `print" ROOMS.... ` adding multiple spaces before it – Padraic Cunningham Nov 14 '15 at 19:17
  • I think you did not understand.what i meant was: displaying the availability of rooms in tabular form with the decrease in each room shown at the end of the program. before it was like the format in #1 but i want it to be like the one in #2 – vanikavaisya trust Nov 14 '15 at 19:17
  • try tabulate or some similar plugin. http://stackoverflow.com/questions/9535954/python-printing-lists-as-tabular-data – Vikash Singh Nov 15 '15 at 14:11
  • sorry, but when i use import tabulate,it says no module named tabulate – vanikavaisya trust Nov 15 '15 at 14:22
  • for that you have to install the module. Any ways i have made a more structured code. see if that works for you. – Vikash Singh Nov 15 '15 at 14:29
  • Few things, structure and minimize code. for structure check pep_8 convention. Install pep8 and pep8 lint in siblime/atom editor. Second. OOP is a real world replication. Basic thinking applies. eg: does hotel extend reservation in real world? Ans:no. So there is something you are doing wrong while approaching the problem. Hotel has a feature (reservation). You can have a reservation class. But ideally hotel should not extend reservation rather encapsulate it so that you can only make reservation at a hotel. hope this makes sense. – Vikash Singh Nov 15 '15 at 14:38

2 Answers2

0
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

Sahib Navlani
  • 68
  • 1
  • 12
0
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
Vikash Singh
  • 13,213
  • 8
  • 40
  • 70
  • in the question , i wanted the decrease in room after reservation to be displayed like in the tabular form also. sorry,for the inconvinience – vanikavaisya trust Nov 15 '15 at 14:49
  • Thank you for your kind help. Its time for me to go. Hope i could solve this.Thank you. – vanikavaisya trust Nov 15 '15 at 14:56
  • when posh cabana is reserved, no should decrease from 13 to 12. which should be displayed at the end in tabular form. along with the other rooms. – vanikavaisya trust Nov 15 '15 at 14:57
  • ok. for that you just need to decrease the unit count and call the method hotel.get_current_status() again. That's it. Shall i write the code for that as well ?? – Vikash Singh Nov 15 '15 at 15:03
  • when i insert it into main class, i get total amount as zero. – vanikavaisya trust Nov 16 '15 at 17:36
  • hi, can you share some detail? how are you integrating it to main class? if possible add code here or link to some online code hosting site. not a problem. – Vikash Singh Nov 16 '15 at 18:24
  • Thank you so much for your help. I removed some lines and added your program and it worked.!! Thank you for not giving up and for spending your time and effort for solving my problem and having the patience to make me realize the mistake.Wish i could do the same.If you hadn't helped,then i would have spend so much time over the wrong idea and would get no result. May god bless you! – vanikavaisya trust Nov 16 '15 at 19:30
  • hehehehe :) thanks for the nice words. Stackoverflow is awesome, members go out of their way to help me when i need it. love that i can give something back to the community. Btw, up-vote and approving the answers helps me back so np :) – Vikash Singh Nov 16 '15 at 19:38
  • hi, i am making a report of this program. Could you kindly explain what is being done in get_current_status and make_reservation?? What is the significance of the statements in get current_status(eg.row format)?? Thank you! – vanikavaisya trust Nov 20 '15 at 19:59
  • row format is controlling how the values are getting printed. if you just consider this part row_format = '{:>5} {:<30}' then whatever first value we print gets five places to be printed. If the string length is 6 that string will spill over and we will loose the tabular structure. Also the values are right aligned in the 5 places. then we are adding a space before the next value. The next values has 30 places to be printed and is left aligned. Let me know if you have more question. – Vikash Singh Nov 20 '15 at 20:14
  • Also up-vote comments and answers that you find helpful. It might help others also. – Vikash Singh Nov 20 '15 at 20:14
  • I also have a doubt about print row_format.format(*self.header)(significance of the *?) , for key in self.hotel_room: and the statements beneath it.Thankyou! – vanikavaisya trust Nov 20 '15 at 20:29
  • in *self.header * is basically to expand the list and pass it as parameters. So the row_format.format('a','b','c','d') will work. Because row_format is expecting 4 parameters. But if we pass the header list directly that's just 1 parameter. So we split it open and pass each value as a parameter. You can read more on that here : http://stackoverflow.com/questions/400739/what-does-asterisk-mean-in-python – Vikash Singh Nov 20 '15 at 20:50
  • about for key in self.hotel_room: the key basically takes the key of the dictionary. So if you want to iterate over a dictionary like say dictin = {"1":"a","2":"b"} for key in dictin: the key value will first be "1" and then it will be "2". To get "a" and "b" we will call dictin[key]. That will return "a" and "b". – Vikash Singh Nov 20 '15 at 20:53
  • In row_format.format(*self.header), is format(just before the bracket) a predefined function in python??? sorry for the trouble.Thank you! – vanikavaisya trust Nov 21 '15 at 15:11
  • Yeah. And basically its a method in string object. To see it yourself you can run this simple code. a = ""; dir(a); this will list all methods supported in string. You can see format in there. :) – Vikash Singh Nov 21 '15 at 15:26
  • @vanikavaisyatrust no problem, glad to help. Just one thing, please up-vote the comments that help you resolve your doubts regarding your question :) – Vikash Singh Nov 21 '15 at 15:31
  • how do you do that?uploading comments? – vanikavaisya trust Nov 21 '15 at 15:31
  • On the left side of each comment/answer you get an upvote icon/ report icon. you can chose and click :) – Vikash Singh Nov 21 '15 at 15:35
  • i already accepted this answer as the best answer. Can't upvote it because it says i need, like 15 reputations.Thank you! – vanikavaisya trust Nov 21 '15 at 15:45
  • oh yeah. You just started the account. Hehehehe . my bad. – Vikash Singh Nov 21 '15 at 15:52