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.
Just cleaned the init function up a little bit. we don't need to use the else part of the if statement if we set:
self.age = initialAge on the first line and then just set self.age = 0 if self.age < 0.
Thank you for the discussion!
classPerson:def__init__(self,initialAge):self.age=initialAgeifself.age<0:print("Age is not valid, setting age to 0.")self.age=0defamIOld(self):ifself.age<13:print("You are young.")elifself.age>=13andself.age<18:print("You are a teenager.")else:print("You are old.")defyearPasses(self):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
Day 4: Class vs. Instance
You are viewing a single comment's thread. Return to all comments →
Just cleaned the init function up a little bit. we don't need to use the else part of the if statement if we set: self.age = initialAge on the first line and then just set self.age = 0 if self.age < 0.
Thank you for the discussion!