Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a905c65

Browse files
Day 4: Class vs. Instance
1 parent c232419 commit a905c65

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

‎Day 4: Class vs. Instance.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
class Person:
2+
age = 0
3+
def __init__(self,initialAge):
4+
# Add some more code to run some checks on initialAge
5+
if (initialAge>0):
6+
self.age = initialAge
7+
else:
8+
print("Age is not valid, setting age to 0.")
9+
def amIOld(self):
10+
# Do some computations in here and print out the correct statement to the console
11+
if (self.age<13):
12+
print("You are young.")
13+
elif (self.age >=13) and (self.age<18):
14+
print("You are a teenager.")
15+
else:
16+
print("You are old.")
17+
def yearPasses(self):
18+
# Increment the age of the person in here
19+
self.age = self.age + 1
20+
21+
t = int(input())
22+
for i in range(0, t):
23+
age = int(input())
24+
p = Person(age)
25+
p.amIOld()
26+
for j in range(0, 3):
27+
p.yearPasses()
28+
p.amIOld()
29+
print("")

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /