love

วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558

Lab7 - Find/Count number of student with age < 30

def setup():
   
    bmi = [student( "Oat" ,1,18,52,165)
           ,student("Nice",2,19,50,170)
           ,student("Loemax",3,19,75,170)
           ,student("Shin",4,19,63,168)]
    i = 0
    age = 0
    while(i<len(bmi)):
        age = age + bmi[i].get_age()
        i = i+1
    average_age = age / len(bmi)
    i = 0
    count = 0
    while(i<len(bmi)):
        age = bmi[i].get_age()
        if(age<30):
            count = count + 1
        i = i+1
    print("Count : ",count)

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
        self.bmi = self.weight/((self.height/100)*(self.height/100))
       
    def get_age(self):
        return self.age
   
    def display(self):
        print("Name : ",self.name)
        print("Student ID : ",self.id)
        print("Age : ",self.age)
        print("Weight : ",self.weight)
        print("Height : ",self.height)
        print("")
       
setup()

ไม่มีความคิดเห็น:

แสดงความคิดเห็น