Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5061fbf

Browse files
authored
Merge pull request#255 from Eeshan2001/main
Added Parking lot system file
2 parents32d0ff8 +5ce38ca commit5061fbf

File tree

5 files changed

+184
-0
lines changed

5 files changed

+184
-0
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
importVehicle
2+
importargparse
3+
importsys
4+
5+
ifsys.version_info[0]==2:
6+
input=raw_input
7+
8+
classParkingLot:
9+
def__init__(self):
10+
self.capacity=0
11+
self.slotid=0
12+
self.numOfOccupiedSlots=0
13+
14+
defcreateParkingLot(self,capacity):
15+
self.slots= [-1]*capacity
16+
self.capacity=capacity
17+
returnself.capacity
18+
19+
defgetEmptySlot(self):
20+
foriinrange(len(self.slots)):
21+
ifself.slots[i]==-1:
22+
returni
23+
24+
defpark(self,regno,color):
25+
ifself.numOfOccupiedSlots<self.capacity:
26+
slotid=self.getEmptySlot()
27+
self.slots[slotid]=Vehicle.Car(regno,color)
28+
self.slotid=self.slotid+1
29+
self.numOfOccupiedSlots=self.numOfOccupiedSlots+1
30+
returnslotid+1
31+
else:
32+
return-1
33+
34+
defleave(self,slotid):
35+
36+
ifself.numOfOccupiedSlots>0andself.slots[slotid-1]!=-1:
37+
self.slots[slotid-1]=-1
38+
self.numOfOccupiedSlots=self.numOfOccupiedSlots-1
39+
returnTrue
40+
else:
41+
returnFalse
42+
43+
defstatus(self):
44+
print("Slot No.\tRegistration No.\tColour")
45+
foriinrange(len(self.slots)):
46+
ifself.slots[i]!=-1:
47+
print(str(i+1)+"\t\t"+str(self.slots[i].regno)+"\t\t"+str(self.slots[i].color))
48+
else:
49+
continue
50+
51+
defgetRegNoFromColor(self,color):
52+
53+
regnos= []
54+
foriinself.slots:
55+
56+
ifi==-1:
57+
continue
58+
ifi.color==color:
59+
regnos.append(i.regno)
60+
returnregnos
61+
62+
defgetSlotNoFromRegNo(self,regno):
63+
64+
foriinrange(len(self.slots)):
65+
ifself.slots[i].regno==regno:
66+
returni+1
67+
else:
68+
continue
69+
return-1
70+
71+
72+
defgetSlotNoFromColor(self,color):
73+
74+
slotnos= []
75+
76+
foriinrange(len(self.slots)):
77+
78+
ifself.slots[i]==-1:
79+
continue
80+
ifself.slots[i].color==color:
81+
slotnos.append(str(i+1))
82+
returnslotnos
83+
84+
defshow(self,line):
85+
ifline.startswith('create_parking_lot'):
86+
n=int(line.split(' ')[1])
87+
res=self.createParkingLot(n)
88+
print('Created a parking lot with '+str(res)+' slots')
89+
90+
elifline.startswith('park'):
91+
regno=line.split(' ')[1]
92+
color=line.split(' ')[2]
93+
res=self.park(regno,color)
94+
ifres==-1:
95+
print("Sorry, parking lot is full")
96+
else:
97+
print('Allocated slot number: '+str(res))
98+
99+
elifline.startswith('leave'):
100+
leave_slotid=int(line.split(' ')[1])
101+
status=self.leave(leave_slotid)
102+
ifstatus:
103+
print('Slot number '+str(leave_slotid)+' is free')
104+
105+
elifline.startswith('status'):
106+
self.status()
107+
108+
elifline.startswith('check_car_number_with_carcolor'):
109+
color=line.split(' ')[1]
110+
regnos=self.getRegNoFromColor(color)
111+
print(', '.join(regnos))
112+
113+
elifline.startswith('check_slot_number_with_carcolor'):
114+
color=line.split(' ')[1]
115+
slotnos=self.getSlotNoFromColor(color)
116+
print(', '.join(slotnos))
117+
118+
elifline.startswith('check_slot_number_with_carno'):
119+
regno=line.split(' ')[1]
120+
slotno=self.getSlotNoFromRegNo(regno)
121+
ifslotno==-1:
122+
print("Not found")
123+
else:
124+
print(slotno)
125+
elifline.startswith('exit'):
126+
exit(0)
127+
128+
defmain():
129+
130+
parkinglot=ParkingLot()
131+
parser=argparse.ArgumentParser()
132+
parser.add_argument('-f',action="store",required=False,dest='src_file',help="Input File")
133+
args=parser.parse_args()
134+
135+
ifargs.src_file:
136+
withopen(args.src_file)asf:
137+
forlineinf:
138+
line=line.rstrip('\n')
139+
parkinglot.show(line)
140+
else:
141+
whileTrue:
142+
line=input("$ ")
143+
parkinglot.show(line)
144+
145+
if__name__=='__main__':
146+
print("----------Welcome to Low Level Parking Lot System-----------------")
147+
print("Type following commands to perform operations on Parking system")
148+
print("1. create_parking_lot n (n=capacity)")
149+
print("2. park car_number var_color")
150+
print("3. status")
151+
print("4. leave x (x=slot number)")
152+
print("5. check_car_number_with_carcolor car_color")
153+
print("6. check_slot_number_with_carcolor car_color")
154+
print("7. check_slot_number_with_carno car_no")
155+
print("Exit")
156+
print("-------------------------------------------------------------------")
157+
main()
268 KB
Binary file not shown.

‎ParkingLot-master/Vehicle.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
classVehicle:
2+
def__init__(self,regno,color):
3+
self.color=color
4+
self.regno=regno
5+
6+
classCar(Vehicle):
7+
8+
def__init__(self,regno,color):
9+
Vehicle.__init__(self,regno,color)
10+
11+
defgetType(self):
12+
return"Car"
851 Bytes
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
create_parking_lot 6
2+
park MH-12-LM-7754 white
3+
park GJ-11-FM-3421 white
4+
park DL-01-KL-0786 black
5+
park JH-04-AK-8654 red
6+
park MH-12-TR-6636 blue
7+
park KA-01-AR-2342 black
8+
leave 4
9+
status
10+
park KA-01-P-333 white
11+
park DL-12-AA-9999 white
12+
check_car_number_with_carcolor white
13+
check_slot_number_with_carcolor white
14+
check_slot_number_with_carno MH-12-LM-7754
15+
check_slot_number_with_carno KA-01-AR-2342

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp