-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path17.5.py
More file actions
57 lines (46 loc) · 1.31 KB
/
17.5.py
File metadata and controls
57 lines (46 loc) · 1.31 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
#coding:utf-8
from __future__ import print_function, division
class Kangaroo:
"""
A Kangaroo is a marsupial.
"""
def __init__(self, name, contents=[]):
"""
Initialize the pouch contents.
name: string
contents: initial pouch contents.
"""
self.name = name
self.pouch_contents = contents
def __init__(self, name, contents=None):
"""
Initialize the pouch contents.
name: string
contents: initial pouch contents.
"""
self.name = name
if contents == None:
contents = []
self.pouch_contents = contents
def __str__(self):
"""
Return a string representaion of this Kangaroo.
"""
t = [self.name + ' has pouch contents:']
for obj in self.pouch_contents:
s = ' ' + object.__str__(obj)
t.append(s)
return '\n'.join(t)
def put_in_pouch(self, item):
"""
Adds a new item to the pouch contents.
item: object to be added
"""
self.pouch_contents.append(item)
kanga = Kangaroo('Kanga')
roo = Kangaroo('Roo')
kanga.put_in_pouch('wallet')
kanga.put_in_pouch('car keys')
kanga.put_in_pouch(roo)
print(kanga)
print(roo)