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(self):
print("Name :",self.name)
print("ID :",self.ID)
print("Age :",self.age)
print("Weight :",self.weight)
print("Height :",self.height)
def get_weight(self):
return self.weight
def get_height(self):
return self.height
def setup():
std = [Student("ant",58001,39,55,165),
Student("bird",58010,25,75,170),
Student("cat",58011,19,44,155),
Student("dog",58100,30,72,169),
Student("eagle",58101,22,70,178),
Student("frog",58110,18,100,175)]
print("Number of students with BMI > 25 =",find_numBMI_greaterthan25(std))
i = 0
while(i < len(std)):
if(calBMI(std[i]) > 25):
print()
std[i].display()
print("BMI : %.2f"%calBMI(std[i]))
i += 1
def calBMI(student):
highM = student.get_height()/100
bmi = student.get_weight()/(highM*highM)
return bmi
def find_numBMI_greaterthan25(student):
i = 0
count = 0
while(i < len(student)):
if(calBMI(student[i]) > 25):
count += 1
i += 1
return count
setup()
ไม่มีความคิดเห็น:
แสดงความคิดเห็น