Parking Lot
class ParkingLot(object):
def __init__(self):
self.__two_wheeler = []
self.__four_wheeler = []
self.__two_wheeler_slots = 200
self.__four_wheeler_slots = 100
def park_two_wheeler(self, obj):
if self.is_parking_lot_full():
return -1
else:
self.__two_wheeler.append(obj)
self.__two_wheeler_slots -= 1
def park_four_wheeler(self, obj):
if self.is_parking_lot_full():
return -1
else:
self.__four_wheeler.append(obj)
self.__four_wheeler_slots -= 1
def available_two_wheeler_slots(self):
return self.__two_wheeler_slots
def available_four_wheeler_slots(self):
return self.__four_wheeler_slots
def is_parking_lot_full(self):
if self.__two_wheeler_slots == 0 and self.__four_wheeler_slots == 0:
return 1
else:
return 0
def parking_lot_details(self):
if self.is_parking_lot_full():
status = "Full"
else:
status = {'Available Two Wheeler Slots' :
self.available_two_wheeler_slots(),
'Available Four Wheeler Slots' :
self.available_four_wheeler_slots()}
return {'Parked_Two_Wheelers' : self.__two_wheeler,
'Parked_Four_Wheelers' : self.__four_wheeler,
'Status' : status}
def get_parked_two_wheelers(self):
return self.__two_wheeler
def get_parked_four_wheelers(self):
return self.__four_wheeler
class Vehicle(object):
def __init__(self, name, model, number):
self._name = name
self._model = model
self._number = number
class Two_Wheeler(Vehicle):
def get_details(self):
return {'Name' : self._name, 'Model' : self._model, 'Number' : self._number}
class Four_Wheeler(Vehicle):
def get_details(self):
return {'Name' : self._name, 'Model' : self._model, 'Number' : self._number}
if __name__ == '__main__':
parking_lot = ParkingLot()
while True:
print("\n\t*********** PARKING LOT ***********")
try:
userinput = int(input("\n\t\t
1. Park Two Wheeler\n\t\t2. Park Four Wheeler\n\t\t
3. Two Wheeler Slots\n\t\t4. Four Wheeler Slots\n\t\t
5. Get Parked Two Wheelers\n\t\t6. Get Parked Four Wheelers\n\t\t
7. Parking Lot Details\n\t\t8. Close Parking Lot\n>>>> "))
except:
print("\nPlease Enter Valid Input!!")
continue
if userinput == 1:
name = input("\nName: ")
model = input("\nModel: ")
number = input("\nNumber: ")
obj = Two_Wheeler(name, model, number)
parking_lot.park_two_wheeler(obj)
print("\nParked Successfully!!")
elif userinput == 2:
name = input("\nName: ")
model = input("\nModel: ")
number = input("\nNumber: ")
obj = Two_Wheeler(name, model, number)
parking_lot.park_four_wheeler(obj)
print("\nParked Successfully!!")
elif userinput == 3:
print("\nAvailable Two Wheeler Slots: ",
parking_lot.available_two_wheeler_slots())
elif userinput == 4:
print("\nAvailable Four Wheeler Slots: ",
parking_lot.available_four_wheeler_slots())
elif userinput == 5:
two_wheelers = parking_lot.get_parked_two_wheelers()
if len(two_wheelers) == 0:
print("\nNo Two Wheelers Parked!!")
else:
print("\n***** Parked Two Wheelers *****")
for two_wheeler in two_wheelers:
details = two_wheeler.get_details()
print("\nName:", details['Name'])
print("Model:", details['Model'])
print("Number:", details['Number'])
elif userinput == 6:
four_wheelers = parking_lot.get_parked_four_wheelers()
if len(four_wheelers) == 0:
print("\nNo Four Wheelers Parked!!")
else:
print("\n***** Parked Four Wheelers *****")
for four_wheeler in four_wheelers:
details = four_wheeler.get_details()
print("\nName:", details['Name'])
print("Model:", details['Model'])
print("Number:", details['Number'])
elif userinput == 7:
print("\n****** Parking Lot Details ******")
details = parking_lot.parking_lot_details()
print("Parked_Two_Wheelers:", details['Parked_Two_Wheelers'])
print("Parked_Four_Wheelers:", details['Parked_Four_Wheelers'])
print("Status:", details['Status'])
elif userinput == 8:
exit()
else:
print("\nPlease Enter Valid Input!!")
continue
# Output
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> wewe
# Please Enter Valid Input!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 11
# Please Enter Valid Input!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 3
# Available Two Wheeler Slots: 200
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 4
# Available Four Wheeler Slots: 100
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 5
# No Two Wheelers Parked!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 6
# No Four Wheelers Parked!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 7
# ****** Parking Lot Details ******
# Parked_Two_Wheelers: []
# Parked_Four_Wheelers: []
# Status: {'Available Two Wheeler Slots': 200, 'Available Four Wheeler Slots': 100}
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 1
# Name: Discover
# Model: Bajaj
# Number: MH-AB-1234
# Parked Successfully!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 1
# Name: Shine
# Model: Honda
# Number: MH-XY-4321
# Parked Successfully!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 3
# Available Two Wheeler Slots: 198
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 4
# Available Four Wheeler Slots: 100
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 5
# ***** Parked Two Wheelers *****
# Name: Discover
# Model: Bajaj
# Number: MH-AB-1234
# Name: Shine
# Model: Honda
# Number: MH-XY-4321
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 6
# No Four Wheelers Parked!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 2
# Name: Brezza
# Model: Maruti Suzuki
# Number: MH-BA-4578
# Parked Successfully!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 2
# Name: Creta
# Model: Hyundai
# Number: MH-YX-8765
# Parked Successfully!!
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 4
# Available Four Wheeler Slots: 98
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 3
# Available Two Wheeler Slots: 198
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 6
# ***** Parked Four Wheelers *****
# Name: Brezza
# Model: Maruti Suzuki
# Number: MH-BA-5678
# Name: Creta
# Model: Hyundai
# Number: MH-YX-8765
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 7
# ****** Parking Lot Details ******
# Parked_Two_Wheelers: [<__main__.Two_Wheeler object at 0x000001D46B113E80>, <__main__.Two_Wheeler object at 0x000001D46B113F70>]
# Parked_Four_Wheelers: [<__main__.Two_Wheeler object at 0x000001D46B113D60>, <__main__.Two_Wheeler object at 0x000001D46B113FA0>]
# Status: {'Available Two Wheeler Slots': 198, 'Available Four Wheeler Slots': 98}
# *********** PARKING LOT ***********
# 1. Park Two Wheeler
# 2. Park Four Wheeler
# 3. Two Wheeler Slots
# 4. Four Wheeler Slots
# 5. Get Parked Two Wheelers
# 6. Get Parked Four Wheelers
# 7. Parking Lot Details
# 8. Close Parking Lot
# >>>> 8
Comments
Post a Comment