We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
classPerson:def__init__(self,initialAge):# Add some more code to run some checks on initialAgeifinitialAge<0:self.age=0print('Ageisnotvalid,settingageto0.')else:self.age=initialAgedefamIOld(self):# Do some computations in here and print out the correct statement to the consoleifself.age<13:print('Youareyoung.')elifself.age<18:print('Youareateenager.')else:print('Youareold.')defyearPasses(self):# Increment the age of the person in here self.age+=1
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Class vs. Instance
You are viewing a single comment's thread. Return to all comments →
Python 3