-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPythonPractice.py
More file actions
59 lines (47 loc) · 1.32 KB
/
Copy pathPythonPractice.py
File metadata and controls
59 lines (47 loc) · 1.32 KB
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
53
54
55
56
57
58
59
"""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
if len(self.items) > 0:
for item in self.items:
if item == "tophat":
classiness += 2
elif item == "bowtie":
classiness += 4
elif item == "monocle":
classiness += 5
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())