Pastebin
Paste #1227: seat, hall, row, reservation
< previous paste - next paste>
Pasted by tdn
class seat:
def __init__(self, id, score):
self.sold = 0 # Number of times this seat has been sold
self.id = id # Seat id number (written on the seat in the theatre hall)
self.score = score #
def __str__(self):
return "seat(id:%s,score:%s,sold:%s)" % (self.id, self.score, self.sold)
def __repr__(self):
return str(self)
def pp(self):
return str(self)
def __cmp__(self, other):
return cmp(other.score, self.score)
class hall:
def __init__(self, rows):
self.rows = rows
def __str__(self):
return "hall(rows:%s)" % self.rows
def __repr__(self):
return str(self)
def pp(self):
"""Return hall as a pretty string"""
res = "hall("
for r in self.rows:
res += "\n %s" % r.pp()
res += "\n)"
return res
class row:
def __init__(self, id, seats):
self.id = id
self.seats = []
self.vacant = 0
for s in seats:
self.seats.append(s)
self.vacant += 1
def __str__(self):
return "row(id:%s,seats:%s,vacant:%s)" % (self.id, self.seats, self.vacant)
def __repr__(self):
return str(self)
def next_available(self):
return len(self.seats) - self.vacant
def pp(self):
res = "row( id: %s, vacant: %s, " % (self.id, self.vacant)
for s in self.seats:
res += "\n %s" % (s.pp())
res += "\n )"
return res
class reservation:
def __init__(self, id, len):
self.len = len
self.id = id
self.seats = []
def __str__(self):
return "reservation(len:%s,seats:%s)" % (self.len, self.seats)
def __repr__(self):
return str(self)
def pp(self):
res = "reservation(id: %s, len: %s" % (self.id, self.len)
for s in self.seats:
res += "\n %s" % s.pp()
res += "\n)"
return res
New Paste
Go to most recent paste.