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

Lab7-student

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 get_weight(self):
      return self.weight

   def get_height(self):
      return self.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 setup():
   S =[student('jinx',58102,18,44,164),
       student('Vi',58201,19,65,169),
       student('Kat',58101,20,70,160)]
   i = 0
   while(i<len(S)):
      S[i].display()
      print('BMI:',BMI(S,i))
      print()
      i+=1

   print('There is',count_over_25_BMI(S),'student who got BMI over 25')
   find_over_25_BMI(S)

   print('There is',count_weight_less_than_50(S),'student who got weight less than 50')
   find_weight_less_than_50(S)

   print('minimum weight of students is',find_minimum_weight(S))
 
def BMI(S,i):
   BMI = S[i].get_weight()/(S[i].get_height()/100)**2
   return BMI

def count_over_25_BMI(array):
   i = 0
   count = 0
   while(i<len(array)):
      if(BMI(array,i)>25):
         count+=1
      i+=1
   return count

def find_over_25_BMI(array):
   i = 0
   print("Let's have a look who got BMI over 25")
   while(i<len(array)):
      if(BMI(array,i)>25):
         array[i].display()
         print()
      i+=1

def count_weight_less_than_50(array):
   i = 0
   count = 0
   while(i<len(array)):
      if(array[i].weight<50):
         count+=1
      i+=1
   return count

def find_weight_less_than_50(array):
   i = 0
   print("Let's have a look who got weight less than 50")
   while(i<len(array)):
      if(array[i].get_weight()<50):
         array[i].display()
      i+=1  

def find_minimum_weight(array):
   i = 0
   minimun_weight = array[i].get_weight()
   while(i<len(array)):
      if(minimun_weight>array[i].get_weight()):
         minimun_weight = array[i].get_weight()
      i = i+1
   return minimun_weight    
setup()

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

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