-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgumpball_machine.py
More file actions
41 lines (30 loc) · 998 Bytes
/
gumpball_machine.py
File metadata and controls
41 lines (30 loc) · 998 Bytes
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
import random
class gumball(object):
def __init__(self, value, color):
self.value = value
self.color = color
class gumball_machine(object):
def __init__(self):
self.container = []
def spit(self):
gumba = random.choice(self.container)
print(gumba.value, gumba.color)
self.container.remove(gumba)
return gumba
def load(self, gumballobj):
self.container.append(gumballobj)
#driver code:
my_gumball_machine = gumball_machine()
gumball1 = gumball('test1', 'testcolor')
my_gumball_machine.load(gumball('cotton candy', 'pink'))
my_gumball_machine.load(gumball('green apple', 'green'))
my_gumball_machine.load(gumball('strawberry', 'red'))
# print(my_gumball_machine.spit())
print(len(my_gumball_machine.container))
for i in my_gumball_machine.container:
print(i.value, i.color)
print()
print(my_gumball_machine.spit())
print()
for i in my_gumball_machine.container:
print(i.value, i.color)