Skip to content

Commit 337c658

Browse files
committed
kid class
1 parent a855ae6 commit 337c658

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

newcodes/answers/q61.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env python
2+
# coding=utf-8
3+
4+
class SchoolKid:
5+
def __init__(self, name, years):
6+
self.name = name
7+
self.years = years
8+
9+
def get_name(self):
10+
return self.name
11+
12+
def get_years(self):
13+
return self.years
14+
15+
def change_name(self, new_name):
16+
self.name = new_name
17+
return self.name
18+
19+
def change_years(self, new_years):
20+
self.years = new_years
21+
return self.years
22+
23+
24+
class ExaggeratingKid(SchoolKid):
25+
def get_years(self):
26+
return self.years + 2
27+
28+
29+
if __name__ == "__main__":
30+
tom = SchoolKid("Tom", 12)
31+
print(tom.get_name())
32+
print(tom.get_years())
33+
tom.change_years(28)
34+
print(tom.get_years())
35+
36+
john = ExaggeratingKid("John", 13)
37+
print(john.get_name())
38+
print(john.get_years())

0 commit comments

Comments
 (0)