HackerRank Daily challenge solution-Day 4-Class vs Instance


Python program for hackerRank Daily challenge Day 4-Class vs Instance

-Dinesh Kumar E


Code:

class Person:

    def __init__(self,initialAge):

        selfage=0

        if initialAge<0:

            print("Age is not valid, setting age to 0.")

        else:

            selfage=initialAge

    def amIOld(self):

        if age<13:

            print("You are young.")

        elif 13<=age<18:

            print("You are a teenager.")

        elif age>=18:

            print("You are old.")

    def yearPasses(self):

        global age

        age+=1

t = int(input())

for i in range(0, t):

    age = int(input())         

    p = Person(age)  

    p.amIOld()

    for j in range(0, 3):

        p.yearPasses()       

    p.amIOld()

    print("") 

Comments

Popular Posts