[Solved] Hotel Booking Problem with Python

Hotel Booking Problem: Prasanna starts a hotel business. He has many hotels spread across the country which he makes available on different social sites for booking. But his business was not making much as his hotels were not much exposed. One of his friends Mahadev was a Software Engineer. He finds that Prasanna is facing a fatal fall in business, so he thinks of helping him by writing a code that would display the Prasanna’s hotels available in that area. Prasanna was happy that his business would come to a track as Mahadev was helping him. Let’s help Mahadev to write code as per the requirement.

Create an abstract class HotelBooking with the following abstract method.

MethodDescription
show_hotel(city)This method should be used in all extended classes.

Create class MakeMyTrip with the following attributes.

variableDataType
hotel_listDictionary

Use __init__() method to initialize the variables.
Use the following methods in MakeMyTrip Class with abstract class in it.

MethodDescription
show_hotel(city)This method will receive the city and display hotel details.If not city is found with the given name, then display ‘No results found’

Create class ClearTrip with the following attributes.

variableDataType
hotel_listDictionary

Use __init__() method to initialize the variables.
Use the following methods in clearTrip Class with abstract class in it.

MethodDescription
show_hotel(city)This method will receive the city and display hotel details.If not city is found with the given name, then display ‘No results found’

Create class Trivago with the following attributes.

variableDataType
hotel_listDictionary

Use __init__() method to initialize the variables.
Use the following methods in Trivago Class with abstract class in it.

MethodDescription
show_hotel(city)This method will receive the city and display hotel details.If not city is found with the given name, then display ‘No results found’

NOTE
For each class include the data of the Dictionary attribute(hotel_list) which consists of the city details that are stored with key as the city name and the corresponding value consists of the list of hotel names.

MakeMyTrip :

self.hotel_list = {‘Mysore’:[‘Sugamya corner–1500 per day’,’Mysorepalace–2050 per day’],’Bangalore’:[‘Jigar corner–1500 per day’,’Marshpalace–2050 per day’],’Mangalore’:[‘Karawali corner–1500 per day’,’Mangalorepalace–2050 per day’]}

Trivago :

self.hotel_list = {‘Bangalore’:[‘Kanakazana corner–1250 per day’,’Bangalorepalace–2150 per day’],’Mysore’:[‘Sugamya corner–1500 per day’,’Mysorepalace–2050 per day’]}

ClearTrip:

self.hotel_list = {‘Mysore’:[‘Sugamya corner–1250 per day’,’Mysorepalace–2250 per day’],’Shivmogha’:[‘Jog jalapatha–1500 per day’,’Murdashwara mata–2050 per day’]}


Sample Input and Output 1:

Menu

1.MakeMyTrip

2.Trivago

3.ClearTrip

Enter your choice

3

Enter city to be searched

Shivmogha

Jog jalapatha–1500 per day

Murdashwara mata–2050 per day

Sample Input and Output 2:

Menu

1.MakeMyTrip

2.Trivago

3.ClearTrip

Enter your choice

3

Enter city to be searched

Shimoga

No results found

Solution

from abc import ABCMeta


class HotelTraif:
    def showTraiff(self, c):
        # fill your code
        if c in self.f:
            # split
            for i in self.f[c]:
                print(i)
        else:
            print("No results found")



class MakeMyTrip(HotelTraif):
    def __init__(self):
        self.f = {'Mysore': ['Sugamya corner--1500 per day', 'Mysorepalace--2050 per day'], 'Bangalore': ['Jigar corner--1500 per day',
                                                                                                          'Marshpalace--2050 per day'], 'Mangalore': ['Karawali corner--1500 per day', 'Mangalorepalace--2050 per day']}

    def showTraiff(self, c):
        # fill your code
        if c in self.f:
            # split
            for i in self.f[c]:
                print(i)
        else:
            print("No results found")


class Trivago(HotelTraif):
    def __init__(self):
        self.f = {'Bangalore': ['Kanakazana corner--1250 per day', 'Bangalorepalace--2150 per day'],
                  'Mysore': ['Sugamya corner--1500 per day', 'Mysorepalace--2050 per day']}

    def showTraiff(self, c):
        # fill your code
        if c in self.f:
            # split
            for i in self.f[c]:
                print(i)
        else:
            print("No results found")

class ClearTrip(HotelTraif):
    def __init__(self):
        self.f = {'Mysore': ['Sugamya corner--1250 per day', 'Mysorepalace--2250 per day'],
                  'Shivmogha': ['Jog jalapatha--1500 per day', 'Murdashwara mata--2050 per day']}

    def showTraiff(self, c):
        # fill your code
        if c in self.f:
            # split
            for i in self.f[c]:
                print(i)
        else:
            print("No results found")



        # Main
# sauravhathi
print("Menu\n1.MakeMyTrip\n2.Trivago\n3.ClearTrip")
n = int(input("Enter your choice\n"))
# fill your code
if n == 1:
    m = MakeMyTrip()
    c = raw_input("Enter city to be searched\n")
    m.showTraiff(c)
elif n == 2:
    t = Trivago()
    c = raw_input("Enter city to be searched\n")
    t.showTraiff(c)
elif n == 3:
    ct = ClearTrip()
    c = raw_input("Enter city to be searched\n")
    ct.showTraiff(c)

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saransh Saurav

Saransh Saurav

Articles: 67

Leave a Reply

Your email address will not be published. Required fields are marked *