'''类继承实现--停车场--面试题2019/6/12'''
import random
class Parking(object):
parking_s = [x for x in range(1, 10)] #所有停车位
def __init__(self):
self.remaining_parking_s = self.parking_s #剩余停车位
class Car(Parking):
def carinto(self):
print("剩余停车位: {}".format(self.remaining_parking_s))
random_parking_s = random.choice(self.remaining_parking_s)
print("随机停车位: {}".format(random_parking_s))
self.remaining_parking_s.remove(random_parking_s)
return self.remaining_parking_s
# 将方法变成属性
@property
def run(self):
print("剩余停车位: {}".format(self.remaining_parking_s))
random_parking_s = random.choice(self.remaining_parking_s)
print("随机停车位: {}".format(random_parking_s))
self.remaining_parking_s.remove(random_parking_s)
return self.remaining_parking_s
c1 = Car()
print(c1.run)
c2 = Car()
print(c2.run)
c3 = Car()
print(c3.run)