在pycharm运行:class ParkingSpot: def init(self, spot_id, status='Available'): self.spot_id = spot_id self.status = status def str(self): return f'Spot ID: {self.spot_id} Status: {self.status}' class ParkingLot: def init(self, num_spots): self.spots = [ParkingSpot(i) for i in range(1, num_spots+1)] def park_vehicle(self, spot_id): spot = self.spots[spot_id-1] if spot.status == 'Available': spot.status = 'Occupied' print(f'Spot {spot_id} is now occupied.') else: print(f'Spot {spot_id} is already occupied.') def release_spot(self, spot_id): spot = self.spots[spot_id-1] if spot.status == 'Occupied': spot.status = 'Available' print(f'Spot {spot_id} is now available.') else: print(f'Spot {spot_id} is already available.') def display_spots(self): for spot in self.spots: print(spot)只显示进程已结束退出代码
时间: 2023-06-02 09:08:33 浏览: 153
:这段代码是一个简单的停车场系统,包括两个类:ParkingSpot(停车位)和ParkingLot(停车场)。其中,停车位具有唯一的ID和状态(默认为“Available”),而停车场由停车位组成。停车场具有三个方法:park_vehicle(停车)、release_spot(释放停车位)和display_spots(显示所有停车位信息)。进程已结束退出代码。
阅读全文