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

LAB 6 About age

def setup():
   name = ['fizz','talon','vayny','darious','zyra']
   iD   = [10161,10164,10163,10054,52151]
   age  = [10,25,30,20,15]
   weight = [ 70 , 60 ,50 ,80,10]
   height = [180 , 190 ,140,120,100 ]
   print("age before sort",age)
   print("age after sort ",sort(age))
   print("index after sort of age",find_index_sort_age(age,sort(age)))
   display(find_index_sort_age(age,sort(age)),name,age,iD,weight,height)

def findAverageAge(age):
   result = 0
   i = 0
   while ( i < len(age)):
      result = result + age[i]
      i = i +1
   result = result  / len(age)
   return result

def find_number_age_less30(age):
   result = []
   i = 0
   while(i < len(age)):
      if (age[i]< 30):
         result = result+[i]
      i = i +1
   return result


def sort(age):
   count = 1 # for count a sort
   check =0
   count_result =0 # for copy value
   result =[]      # copy value of age
   while(count_result < len(age)):
      result = result + [age[count_result]]
      count_result = count_result +1
   while(check==0):
      backup_value = 0
      if(result[count]<result[count-1]):
         backup_value = result[count]
         result[count]  =result[count-1]
         result[count-1]=backup_value
      count = count +1
      if(count == len(result)):
         count =1
      if(check_value(result)):
         check = 1
   return result
 
def check_value(age):
   count = 0
   while(count<len(age)-1):
      if(age[count]>age[count+1]):
         return False
      count = count +1
   return True

def find_index_sort_age(age,sort_age):
   index = []
   count_sort = 0
   count_age = 0
   while(len(index)<len(sort_age)):
      while(count_sort < len(sort_age)):
         if(sort_age[count_sort]== age[count_age]):
            index = index + [count_age]
            count_sort = count_sort +1
            count_age = 0      
         count_age = count_age +1
   return index    
   
def display(index,name,age,iD,weight,height):
   count= 0
   while(count<len(index)):
      print(".............................")
      print ("ID . ",iD[index[count]])
      print ("name   is ",name[index[count]])
      print ("age    is ",age[index[count]])
      print ("weight is ",weight[index[count]])
      print ("height  is ",height[index[count]])
      count = count + 1
       


setup()


ผลลัพธ์
age before sort [10, 25, 30, 20, 15]
age after sort  [10, 15, 20, 25, 30]
index after sort of age [0, 4, 3, 1, 2]
.............................
ID .  10161
name   is  fizz
age    is  10
weight is  70
height  is  180
.............................
ID .  52151
name   is  zyra
age    is  15
weight is  10
height  is  100
.............................
ID .  10054
name   is  darious
age    is  20
weight is  80
height  is  120
.............................
ID .  10164
name   is  talon
age    is  25
weight is  60
height  is  190
.............................
ID .  10163
name   is  vayny
age    is  30
weight is  50
height  is  140

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

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