class vs instance python3

Solutions on MaxInterview for class vs instance python3 by the best coders in the world

showing results for - "class vs instance python3"
Gabby
09 Jun 2020
1class Person:
2    def __init__(self,initialAge):
3        # Add some more code to run some checks on initialAge
4        if initialAge < 0:
5            self.age = 0
6            print("Age is not valid, setting age to 0.")
7        else:
8            self.age = initialAge
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 += 1