駐車場

車の駐車を管理する ParkingLot クラスを作成してください。このクラスは複数の機能を持っています:車を駐車する、車を出庫する、そして残りの駐車スペースの数を報告できる必要があります。
駐車場に駐車できる車を表す Car クラスを作成してください。
以下を実装する必要があります:
  • Car クラス:car_id 属性を持ちます。この属性は車オブジェクトを作成するときに指定します。以降のすべての操作はこの car_id を考慮に入れる必要があります。
  • ParkingLot クラス:
    • total_spots attribute: the total number of parking spots in the parking lot, which should be provided when the parking lot object is created.
    • park(car) method: parks a Car object in the parking lot. If the parking lot is full, it should print Parking lot is full.
    • release(car) method: releases a Car from the parking lot. If the car is not in the parking lot, it should print Car not found in the parking lot.
    • spots_left() method: returns an integer representing the number of available parking spots in the parking lot.
入力
出力
car1 = Car(1); car2 = Car(2); lot = ParkingLot(2); print(lot.spots_left()); lot.park(car1); print(lot.spots_left()); lot.park(car2); print(lot.spots_left()); lot.release(car1); print(lot.spots_left());
2 1 0 1
car1 = Car(1); car2 = Car(2); lot = ParkingLot(1); print(lot.spots_left()); lot.release(car1); print(lot.spots_left()); lot.park(car1); print(lot.spots_left()); lot.park(car2); print(lot.spots_left())
1 Car not found in the parking lot 1 0 Parking lot is full 0
 

Constraints

Time limit: 1 seconds

Memory limit: 512 MB

Output limit: 1 MB

To check your solution you need to sign in
Sign in to continue