-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpocketknife.py
50 lines (42 loc) · 1.84 KB
/
pocketknife.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
42
43
44
45
46
47
48
49
50
class PocketKnife():
#consructor with 2 parameters
def __init__(self, blade, canOpener):
self.blade = blade #whether the blade is open or closed
self.canOpener = canOpener #whether the can opener is open or closed
#interface accessor
#returns current item description with variables
def get_interface(self):
print("Your pocket knife has a standard 3 inch blade attached to it, along with a handy-dandy little can opener.")
# Blade if
if self.blade:
print("The blade on the knife is currently out, watch where you point that thing!")
print("You can close the BLADE the pocket knife.")
else:
print("The blade on the knife is closed, all is well in the world.")
print("You can open the BLADE the pocket knife.")
# Can opener if
if self.canOpener:
print("The can opener is open, may all the unopened cans in the world tremble with fear.")
print("You can close the CAN OPENER on the pocket knife.")
else:
print("The can opener is closed, all the unopened cans in the world can sleep easy.")
print("You can open the CAN OPENER on the pocket knife.")
#checks for UI keywords, calls other setters
def check_input(self, command):
if command == "BLADE" and not self.blade:
self.bladeToggle()
if command == "CAN OPENER" and not self.canOpener:
self.canOpenerToggle()
#blade mutator
#toggles the blade switch
def toggleBlade(self):
self.blade = not self.blade
#can opener mutator
#toggles the can opener switch
def toggleCanOpener(self):
self.canOpener = not self.canOpener
#accessors
def getBlade(self):
return self.blade
def getCanOpener(self):
return self.canOpener