วันเสาร์ที่ 31 ตุลาคม พ.ศ. 2558

Lab 7 - (Class) Find/count number of students with BMI > 25

class student:

    def __init__(self,name,age,weight,height):
        self.name = name
        self.age = age
        self.weight = weight
        self.height = height

    def display(self):
        print(self.name, end = "   ")
        print(self.age, end = "   ")
        print(self.weight, end = "   ")
        print(self.height, end = "   ")
        print()
         
    def get_weight(self):
        return self.weight
     
    def get_height(self):
        return self.height
   
def setup():
    info = [student("Buntun",18,50,160),
            student("FlukeKnub",19,75,199),
            student("PeeJa",19,60,150),
            student("Nutdech",18,58,185),
            student("BasBomba",20,60,180)]
    cal_bmi(info)
   
def cal_bmi(info):
    i = 0
    sum = 0
    while(i<len(info)):
        bmi = info[i].get_weight()/((info[i].get_height()/100)*(info[i].get_height()/100))
        if ( bmi > 25):
            info[i].display()
            print(bmi)
            print()
            sum = sum+1
        i = i+1
    print ("Number member who has bmi more than 25 is",sum )

setup()

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

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