We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c232419 commit a905c65Copy full SHA for a905c65
Day 4: Class vs. Instance.py
@@ -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
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
29
+ print("")
0 commit comments