วันอังคารที่ 24 พฤศจิกายน พ.ศ. 2558

Lab 6 : Find total number of chairs (in the building)

def setup():
   first = [15,13,7,11,9]
   second = [19,12,22,29,25]
   third = [23,20,34,33,35]
   fourth = [49,38,33,45,41]
   floor = [first,second,third,fourth]
 
   ifloor = 0
   total = 0
 
   while(ifloor<len(floor)):
      iroom = 0
      while(iroom<len(floor[ifloor])):
            total = total+floor[ifloor][iroom]
            iroom = iroom+1
      ifloor = ifloor+1
   print("Total number of chairs =",total)



setup()

Lab 6 : Display student records with weight < 50

def setup():
   name = ["Mum" , "Teng" , "Nong" , "Tukky"]
   height = [161,175,177,155]
   weight = [62,49,86,71]
   age = [25,18,52,43]
   i = 0
   while(i<len(weight)):
      if(weight[i]<50):
         print(name[i],age[i],"years old",height[i],"cm.",weight[i],"kg.")
      i = i+1



setup()

Lab 6 : Find/count number of students with weight < 50

def setup():
   name = ["Mum" , "Teng" , "Nong" , "Tukky"]
   height = [161,175,177,155]
   weight = [62,49,86,71]
   age = [25,18,52,43]
   i = 0
   count = 0
   while(i<len(weight)):
      if(weight[i]<50):
         count = count+1
         print(name[i]," = ",weight[i],"kg.")
      i = i+1
   print("Total student weight<50 =",count)


setup()

Lab 6 : Find/count number of students with age < 30

def setup():
   name = ["Mum" , "Teng" , "Nong" , "Tukky"]
   height = [161,175,177,155]
   weight = [62,54,86,71]
   age = [25,18,52,43]
   i = 0
   count = 0
   while(i<len(age)):
      if(age[i]<30):
         count = count+1
         print(name[i]," = ",age[i]," years old")
      i = i+1
   print("Total student age<30 = ",count)


setup()

Lab 6 : Find/count number of students with BMI > 25

def setup():
   name = ["Mum" , "Teng" , "Nong" , "Tukky"]
   height = [161,175,177,155]
   weight = [62,54,86,71]
   age = [25,18,52,43]
   i = 0
   count = 0
   while(i<len(name)):
      if(bmi(weight,height,i)>25):
         count = count+1
         print("BMI = ","%.2f"%bmi(weight,height,i))
      i = i+1
   print("Total student BMI>25 = ",count)
 

def bmi(weight,height,i):
   h = height[i]/100
   bmi = weight[i]/(h*h)
   return bmi

setup()

Lab 6 : Find minimum weight of students

def setup():
   name = ["Mum" , "Teng" , "Nong" , "Tukky"]
   height = [161,175,177,155]
   weight = [62,54,86,71]
   age = [25,18,52,43]
   i = 0
   min = weight[i]
   while(i<len(weight)):
      if(min>weight[i]):
         min = weight[i]
         print(name[i],"is minimum weight of student =",min,"kg.")
      i = i+1
   
 
setup()

Lab 6 : Display student records with BMI > 25

def setup():
   name = ["Mum" , "Teng" , "Nong" , "Tukky"]
   height = [161,175,177,155]
   weight = [62,54,86,71]
   i = 0
   while(i<len(name)):
      if(bmi(weight,height,i)>25):
         print(name[i],height[i],"cm. ",weight[i],"kg. ","BMI = ","%.2f"%bmi(weight,height,i))
      i = i+1
 

def bmi(weight,height,i):
   h = height[i]/100
   bmi = weight[i]/(h*h)
   return bmi

setup()