-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathclassy_identifier.py
52 lines (43 loc) · 1.21 KB
/
classy_identifier.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
51
52
"""You can use this class to represent how classy someone
or something is.
"Classy" is interchangable with "fancy".
If you add fancy-looking items, you will increase
your "classiness".
Create a function in "Classy" that takes a string as
input and adds it to the "items" list.
Another method should calculate the "classiness"
value based on the items.
The following items have classiness points associated
with them:
"tophat" = 2
"bowtie" = 4
"monocle" = 5
Everything else has 0 points.
Use the test cases below to guide you!"""
class Classy(object):
def __init__(self):
self.items = []
def addItem(self, item):
self.items.append(item)
def getClassiness(self):
classiness = 0
classy_objects = {"tophat": 2, "bowtie": 4, "monocle": 5}
for item in self.items:
if item in classy_objects.keys():
classiness += classy_objects[item]
return classiness
#### Test cases ####
me = Classy()
# Should be 0
print(me.getClassiness())
me.addItem("tophat")
# Should be 2
print(me.getClassiness())
me.addItem("bowtie")
me.addItem("jacket")
me.addItem("monocle")
# Should be 11
print(me.getClassiness())
me.addItem("bowtie")
# Should be 15
print(me.getClassiness())