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

Lab6_Data&BMI

def setup():
   names=["Jack",'John','James','Jane']
   idNo=['5801','5802','5803','5804']
   age=[18,32,15,41]
   weight=[60,99,72,50]
   height=[150,162,170,159]
   listthedata(names,idNo,age,weight,height)
   find_moreBmi25(names,weight,height)
def listthedata(names,idNo,age,weight,height):
    i=0
    while(i<len(names)):
         print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
         print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
         print()
         i=i+1
def cal_bmi(i,weight,height):
   bmi=(weight[i])/((height[i]/100)**2)
   return bmi
def find_moreBmi25(names,weight,height):
   i=0
   n=0
   while(i<len(names)):
         if(cal_bmi(i,weight,height)>25):
              print(names[i],'has BMI > 25.')
              n=n+1
         i=i+1
   print(n,' students that have BMI > 25.')

setup()

วันอาทิตย์ที่ 4 ตุลาคม พ.ศ. 2558

Lab5_Find/CountPositiveNo,_and_SumOfPositiveNo,

def setup():
   n=[40,-70,-50,20,-73,79,-61,-77]
   print('sum of positive values in array is ',calpositiveSum(n))
   find_positive(n)
def calpositiveSum(n):
   i=0
   sums=0
   while(i<len(n)):
      if(n[i]>0):
         sums=sums+n[i]
      i=i+1
   return sums
def find_positive(n):
   i=0
   count=0
   while(i<len(n)):
      if(n[i]>0):
         count=count+1
         print('the positive number is in index : ',i)
      i=i+1
   print('the number of positive number is',count)
setup()

Lab5_Find_Maximum_and_its_index

def setup():
   n=[9,79,50,20,34,79,61,77]
   find_max(n)
def find_max(n):
   i=0
   maximum=n[0]
   while(i<len(n)):
      if(maximum<n[i]):
         maximum=n[i]
      i=i+1
   print('max no, is',maximum)
   i=0
   while(i<len(n)):
      if(maximum==n[i]):
         print('the index is',i)
      i=i+1
setup()

Lab5_findMinimum

def setup():
   n=[40,70,50,20,73,79,61,77]
   print("min no. is",find_minimum(n),".")
def find_minimum(n):
   i=0
   minimum=n[0]
   while(i<len(n)):
      if(minimum>n[i]):
           minimum=n[i]
      i=i+1
   return minimum
setup()

Lab5_SumOfArray_and_AVG

def setup():
   n=[40,70,50,20,73,79,61,77]
   print('sum of values in array is ',find_sum(n))
   print('the avg. of array is',find_avg(n))
def find_avg(n):
   avg=(find_sum(n))/len(n)
   return avg
def find_sum(n):
   i=0
   sums=0
   while(i<len(n)):
      sums=sums+n[i]
      i=i+1
   return sums

setup()

Lab5_ShowElement_and_ChangeValues

def setup():
   n=[12,10,50,20,34,79,61,77]
   show_number(n)
def show_number(n):
   i=0
   z=0
   x=int(input())
   while(z<len(n)):
         n[z]=n[z]+x
         z=z+1
   while(i<len(n)):
      print("No. is ",n[i]," and the index is",i)
      i=i+1
setup()