Sunday, November 1, 2015

Lab7 - Find/count number of students with age < 30

class Student:

    def __init__(self,name,id,age,weight,height):
       

        self.name = name

        self.id = id

        self.age = age

        self.weight = weight

        self.height = height


    def display_name(self):
        return self.name
       
    def display_id(self):
        return self.id 
       
    def display_age(self):
        return self.age
       
    def display_weight(self):
        return self.weight
       
    def display_height(self): 
        return self.height

      

def setup():

    a = Student( "Antony" , 11 , 22 , 71 , 165 )

    b = Student( "Mike" , 12 , 23 , 66 , 171 )

    c = Student( "Jacky" , 23 , 21 , 58 , 162 )

    d = Student( "Bank" , 30 , 22 , 60 , 177 )

    e = Student( "Billy" , 1 , 20 , 62 , 180 )

    f = Student( "Biccy" , 3 , 24 , 62 , 181 )

    data = [a,b,c,d,e,f]

    average_age(data)


def average_age(data):
   
    i = 0
   
    count = 0
   
    while(i < len(data)):
       
        if(data[i].display_age() < 30):
           
            count+=1
           
        i+=1
       
    print("Number of students with age < 30 is ",count)    


setup()

No comments:

Post a Comment