Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Parking:
- def __init__(self):
- self.lots = []
- def create_parking(self, floor, lot_size, lot_num):
- self.lots.append([len(self.lots), floor, lot_size, lot_num, 0]) # id, floor, lot_size, lot_num, vehicle_num
- def find_empty_lot(self, target_lot_size):
- for i in range(len(self.lots)):
- (id, floor, lot_size, lot_num, vehicle_num) = self.lots[i]
- if lot_size == target_lot_size and lot_num > vehicle_num:
- return id
- return None
- def park(self, target_lot_size, target_id):
- for i in range(len(self.lots)):
- (id, floor, lot_size, lot_num, vehicle_num) = self.lots[i]
- if id == target_id:
- self.lots[i][4] += 1
- return None
- def exit(self, target_lot_size):
- random.shuffle(self.lots)
- for i in range(len(self.lots)):
- (id, floor, lot_size, lot_num, vehicle_num) = self.lots[i]
- if lot_size == target_lot_size and vehicle_num > 0:
- self.lots[i][4] -= 1
- return None
- def show_status(self):
- for i in range(len(self.lots)):
- print(self.lots[i])
- if __name__=='__main__':
- # test
- parking = Parking()
- parking.create_parking("2F", "S", 3)
- parking.create_parking("1F", "S", 3)
- parking.show_status()
- id = parking.find_empty_lot("S")
- parking.park('S',id)
- parking.show_status()
- parking.exit('S')
- parking.show_status()
Add Comment
Please, Sign In to add comment