OOPS-EQUALS() Hall Booking – __eq__() method – Learn Advanced Python Programming

Praveen works as a Reservation manager, he keeps the record of all the booking details and reservations of the convention halls. But he wants to automate it since manually maintaining all the files consume a lot of time. So, he asks help from the Development team to automate the process which takes the details of ‘n’ number of entries of the halls along with the hall details which includes the name of Hall, Contact, and Address of the user, Booking Date, Cost, and owner of the Hall. Now it needs to find whether the hall is available for registration or not by comparing the name, Phone number, and the booking date of the booking details with available Hall details. Print the details. 
 
Create a Hall class in ‘Hall.py’ with the following attributes.

DataTypeVariable
strname
intphone_number
straddress
Date booking_date
floatcost
strowner

Initialize the attributes using “__init__()” method. 
Use the following methods in Hall class. 

MethodDescription
__eq__(self , obj)Override the __eq__() method and check whether all the details of the hall match or not.’obj’ is an object of newly entered hall details.
display(self)Display all the details of the hall

In ‘Main.py’ get the inputs and call the ‘Hall’ class.

Input Format:

Input consists of an integer ‘n’ indicating the number of entries followed by the details of ‘n’ number of halls. Next, the user needs to enter the hall details to be booked.

Output format:

The output should display “Already registered” if the halls are booked, followed by the booked hall details. 
The output should display “Registration Available” if the hall to be booked is available, followed by the booked hall details and the available hall details.

Refer to sample input and output for formatting specifications.

All text in bold corresponds to the input and the rest corresponds to output.
 
Input-Output Sample 1:
Enter the number of Entries
1
Enter details of Hall 1
Enter Hall name
chandan palace
Enter Phone
9876540321
Enter Address
Chandan Palce,RamakrishnaNagar,Mysore
Enter Date of booking
Dec 12 2017
Enter cost
1243
Enter owner name
Chandan

Enter the Hall details for booking
Enter Hall name
chandan palace
Enter Phone
9876540321
Enter Address
Chandan Palce,RamakrishnaNagar,Mysore
Enter Date of booking
Dec 12 2017
Enter cost
1243
Enter owner name
Chandan

Already Registered

Display the Booked Hall details
Hall name :chandan palace
Phone No : 9876540321
Address :Chandan Palce,RamakrishnaNagar,Mysore
Cost :1243.00
Owner name :Chandan

Input-Output Sample 2:

Enter the number of Entries
1
Enter details of Hall 1
Enter Hall name
palace
Enter Phone
9876540321
Enter Address
Palce,RamakrishnaNagar,Mysore
Enter Date of booking
Dec 12 2017
Enter cost
1243
Enter owner name
Alex


Enter the Hall details for booking
Enter Hall name
Alex palace
Enter Phone
9876540322
Enter Address
Alex Palce,RamakrishnaNagar,Mysore
Enter Date of booking
Dec 13 2017
Enter cost
3477
Enter owner name
Alex

Registration available

Display the Booked Hall details
Hall name :palace
Phone No : 9876540321
Address :Palce,RamakrishnaNagar,Mysore
Cost :1243.00
Owner name :Alex

Hall name :Alex palace
Phone No : 9876540322
Address :Alex Palce,RamakrishnaNagar,Mysore
Cost :3477.00
Owner name :Alex

Solution:

class Hall:

    #Fill your code here
    def __init__(self, name, phone, address, date, cost, owner):
        self.name = name
        self.phone = phone
        self.address = address
        self.date = date
        self.cost = cost
        self.owner = owner
    
    def __str__(self):
        return 'Hall Name: ' + self.name + '\nPhone: ' + str(self.phone) + '\nAddress: ' + self.address + '\nDate: ' + self.date + '\nCost: ' + str(self.cost) + '\nOwner: ' + self.owner

    def __eq__(self, other):
        return self.name == other.name and self.phone == other.phone and self.address == other.address and self.date == other.date and self.cost == other.cost and self.owner == other.owner
        
    def display(self):
        print(self)
from Hall import Hall
import time,datetime

hall_list = list() 
n = int(input("Enter the number of Entries\n"))
for i in range (0,n):
    print("Enter details of Hall",(i+1))
    name = input("Enter Hall name\n")
    phone_number = int(input("Enter Phone\n"))
    address = input("Enter Address\n")
    booking_date = input("Enter Date of booking\n")
    cost = int(input("Enter cost\n"))
    owner = input("Enter owner name\n\n")
    #Parse booking_date as datetime object, create Hall object and add it to list
    
print("Enter the Hall details for booking")
name = input("Enter Hall name\n")
phone_number = int(input("Enter Phone\n"))
address = input("Enter Address\n")
booking_date = input("Enter Date of booking\n")
cost = int(input("Enter cost\n"))
owner = input("Enter owner name\n\n")
#Fill your code here


from Hall import Hall

print('Enter the number of Entries:')

x=int(input())

Halls=[]

for i in range(1,x+1):

  print('Enter details of hall ' +str(i))

  print('Enter Hall name')

  a = input()

  print('Enter Phone')

  b= int(input())

  print('Enter Address')

  c=input()

  print('Enter date of Booking')

  d=input()

  print('Enter cost')

  e=input()

  print('Enter owner name')

  f=input()

  h=Hall(a,b,c,d,e,f)

  Halls.append(h)

print()

print('Enter the Hall details for booking')

print('Enter Hall name')

a1 = input()

print('Enter Phone')

b1= int(input())

print('Enter Address')

c1=input()

print('Enter date of Booking')

d1=input()

print('Enter cost')

e1=input()

print('Enter owner name')

f1=input()

check=Hall(a1,b1,c1,d1,e1,f1)



for k in range(len(Halls)):

  if(Halls[k]==check):

    print()

    print('Already registered')

    print()

    print('Display the Booked Hall details')

    print('hall name:'+Halls[k].name)

    print('Phone No. :'+str(Halls[k].phone))

    print('Address :'+Halls[k].address)

    print('cost :'+str(Halls[k].cost))

    print('owner name :'+Halls[k].owner)

  else:

    print()

    print('Registration available')

    print()

    print('Display the Booked Hall details')

    print('hall name:'+Halls[k].name)

    print('Phone No. :'+str(Halls[k].phone))

    print('Address :'+Halls[k].address)

    print('cost :'+str(Halls[k].cost))

    print('owner name :'+Halls[k].owner)

    print()

    print('hall name:'+check.name)

    print('Phone No. :'+str(check.phone))

    print('Address :'+check.address)

    print('cost :'+str(check.cost))

    print('owner name :'+check.owner)

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

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

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