-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHanmock.py
42 lines (41 loc) · 979 Bytes
/
Hanmock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class Hammock:
def __init__(self):
self.sit = 'empty'
self.list = []
def sitDown(self, name):
if self.sit == 'empty':
self.sit = 'ocupied'
return 'welcome!'
else:
if name in self.list:
return 'welcome!'
else:
self.list.append(name)
return 'sorry, no room'
def leave(self):
if self.sit == 'ocupied':
self.sit = 'empty'
return 1
else:
return 0
myHammock = Hammock()
print myHammock.sitDown('George')
# welcome!
print myHammock.sitDown('Bobby')
# sorry, no room
print myHammock.sitDown('Bobby')
# welcome!
print myHammock.leave()
# 1
print myHammock.leave()
# 0
print myHammock.leave()
# 0
print myHammock.sitDown('Martha')
# welcome!
print myHammock.sitDown('Wilhelm')
# sorry, no room
print myHammock.sitDown('Klaus')
# sorry, no room
print myHammock.sitDown('Wilhelm')
# sorry, no room