0

I am unable to understand the part of a code in python3

class Person: def __init__(self,initialAge,): if (initialAge<0): self.age=0 print("Age is not valid, setting age to 0.") else: self.age=initialAge # Add some more code to run some checks on initialAge def amIOld(self): if (self.age<13): print ("You are young.") elif (self.age>=13 and self.age<18): print("You are a teenager.") else: print ("You are old.") # Do some computations in here and print out the correct statement to the console def yearPasses(self): self.age+=1 # Increment the age of the person in here ###Please tell me what the below written part of code does 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("")

20th Jul 2020, 12:41 PM
Agrata Singh
Agrata Singh - avatar
2 odpowiedzi
+ 1
Agrata Singh ###Please tell me what the below written part of code does 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("") 1. get a input, convert it into number and then assign it to variable t 2. for t number of times get the age and create a Person Object with that age. 3. Calls amIOld function of that Person object which tells whether you are young or teenager or old. 4. Calls yearPasses function of the Person object for three times and again repeating step 3. For example if you give t=2, then you have to enter two ages 16 10 Output: You are a teenager. You are a old. You are young. You are teenager.
20th Jul 2020, 12:56 PM
viknesh vikky
viknesh vikky - avatar
0
its takes a number and saves the number as t. it makes t people instances, asks for an age each time, then advances each person 3 years and checks their age each time, saying wether they are above 18.
20th Jul 2020, 12:59 PM
Slick
Slick - avatar