Estacionamento
Crie uma classe
ParkingLot
que gerencia o estacionamento de carros. Esta classe tem várias funcionalidades: deve ser capaz de estacionar um carro, liberar um carro e informar o número de vagas restantes.Crie uma classe
Car
que representa um carro que pode ser estacionado no estacionamento.Você precisa implementar o seguinte:
- Uma classe
Car
, com um atributocar_id
: deve ser fornecido quando o objeto carro for criado. Todas as operações seguintes devem levar em conta ocar_id
.
- Uma classe
ParkingLot
com: 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 aCar
object in the parking lot. If the parking lot is full, it should printParking lot is full
.release(car)
method: releases aCar
from the parking lot. If the car is not in the parking lot, it should printCar not found in the parking lot
.spots_left()
method: returns an integer representing the number of available parking spots in the parking lot.
Entrada | Saída |
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