วันอังคารที่ 27 ตุลาคม พ.ศ. 2558

LAB 7 replace

def setup():
   set_string = string("A","B","C")
   set_string.display()
   set_string.replace("0","+")
   set_string.display()
   set_string.replace("7","0")
   set_string.display()
   set_string.replace("-","7")
   set_string.display()
   set_string.replace("*","-")
   set_string.display()

   
class string():
   def __init__(self,char1,char2,char3):
      self.char1 =find_row_string(char1)
      self.char2 =find_row_string(char3)
      self.char3 =find_row_string(char3)
 
   def display(self):
      count = 0
      while(count<len(self.char1)):
         print(self.char1[count],self.char2[count],self.char3[count])
         count +=1
 
   def replace(self,replace,getout):
      count_row = 0
      while(count_row<len(self.char1)):
         count_string =0
         self.char1[count_row] = my_replace(self.char1[count_row],getout,replace)
         self.char2[count_row] = my_replace(self.char2[count_row],getout,replace)
         self.char3[count_row] = my_replace(self.char3[count_row],getout,replace)
         count_row +=1
       
   
def my_replace(string,getout,replace):
   result = ""
   i = 0
   while( i < len(string) ):
      if(string[i] == getout):
         result = result + replace
         i = i +len(replace)
      else:
         result = result + string[i]
         i = i +1
   return result  

   
def find_row_string(data):
   count = 0
   result =[]
   while(count<len(data)):
      result +=find_row_char(data[count])
      count  += 1
   return result
 
def find_row_char(data):
   result = []
   result = setKey(data)
   return result
 
def setKey(key):
   row_1_A = "    +    "
   row_2_A = "   + +   "
   row_3_A = "  +   +  "
   row_4_A = " +  +  + "
   row_5_A = "+       +"
   key_A   = [row_1_A,row_2_A,row_3_A,row_4_A,row_5_A]
   row_1_E = "++++++++"
   row_2_E = "++      "
   row_3_E = "++++++++"
   row_4_E = "++      "
   row_5_E = "++++++++"
   key_E   = [row_1_E,row_2_E,row_3_E,row_4_E,row_5_E]
   row_1_C = " +++++++"
   row_2_C = "+++     "
   row_3_C = "++      "
   row_4_C = "+++     "
   row_5_C = " +++++++"
   key_C   = [row_1_C,row_2_C,row_3_C,row_4_C,row_5_C]
   row_1_B = "+++++++ "
   row_2_B = "+      +"
   row_3_B = "+++++++ "
   row_4_B = "+      +"
   row_5_B = "+++++++ "
   key_B   = [row_1_B,row_2_B,row_3_B,row_4_B,row_5_B]
   if(key == 'A'):
      return key_A
   elif(key == 'B'):
      return key_B
   elif(key == 'C'):
      return key_C
   elif(key == 'E'):
      return key_E
   else:
     return ["","","","",""]

setup()
    +      +++++++  +++++++
   + +    +++      +++     
  +   +   ++       ++      
 +  +  +  +++      +++     
+       +  +++++++  +++++++
    0      0000000  0000000
   0 0    000      000     
  0   0   00       00      
 0  0  0  000      000     
0       0  0000000  0000000
    7      7777777  7777777
   7 7    777      777     
  7   7   77       77      
 7  7  7  777      777     
7       7  7777777  7777777
    -      -------  -------
   - -    ---      ---     
  -   -   --       --      
 -  -  -  ---      ---     
-       -  -------  -------
    *      *******  *******
   * *    ***      ***     
  *   *   **       **      
 *  *  *  ***      ***     
*       *  *******  *******

LAB 7 Weight

def setup():
    A = data_student("A",100,10,30,160)
    B = data_student("B",101,5,26,162)
    C = data_student("C",102,15,96,182)
    D = data_student("D",103,4,70,160)
    data = [A,B,C,D]
    print("minimun weight is",find_minimum(data))
    print("count number weight below 50 is",count_weight_low50(data))
    display_low50(data)
     
def display_low50(data):
   count = 0
   while(count<len(data)):
      if(check_low50(data[count].replay_weight())):
         data[count].display()
      count +=1
     
def check_low50(data):
   if(data<50):
      return True
   return False
     
def count_weight_low50(data):
   count = 0
   result = 0
   while(count<len(data)):
      if(check_low50(data[count].replay_weight())):
         result += 1
      count += 1
   return result
     
def find_minimum(data):
   count = 0
   result = data[0].replay_weight()
   while(count<len(data)):
      if(data[count].replay_weight()<result):
         result = data[count].replay_weight()
      count += 1
   return result

class data_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 display(self):
      print(".......................")
      print("ID IS ",self.iD)
      print("name  ",self.name)
      print("age   ",self.age)
      print("weight",self.weight)
      print("height",self.height)

   def replay_weight(self):
      return self.weight

 
 
setup()

minimun weight is 26
count number weight below 50 is 2
.......................
ID IS  100
name   A
age    10
weight 30
height 160
.......................
ID IS  101
name   B
age    5
weight 26
height 162

LAB 7 Age

def setup():
    A = data_student("A",100,10,80,160)
    B = data_student("B",101,5,56,162)
    C = data_student("C",102,15,96,182)
    D = data_student("D",103,4,70,160)
    data = [A,B,C,D]
    print("Everage age is ",find_everage_age(data))
    print("Have student age low 30 about",count_age_low30(data))
    sort_by_age(data)
    display_array(data)
     
def display_array(data):
   count = 0
   while(count<len(data)):
      data[count].display()
      count += 1    
     
def sort_by_age(data):
   count = 1
   while(check(data)):
      if(data[count].replay_age()<data[count-1].replay_age()):
         backup_id = data[count].replay_id()
         backup_name = data[count].replay_name()
         backup_age = data[count].replay_age()
         backup_weight = data[count].replay_weight()
         backup_height = data[count].replay_height()
       
         data[count].get_id(data[count-1].replay_id())
         data[count].get_name(data[count-1].replay_name())
         data[count].get_age(data[count-1].replay_age())
         data[count].get_weight(data[count-1].replay_weight())
         data[count].get_height(data[count-1].replay_height())
       
         data[count-1].get_id(backup_id)
         data[count-1].get_name(backup_name)
         data[count-1].get_age(backup_age)
         data[count-1].get_height(backup_weight)
         data[count-1].get_weight(backup_height)
      count += 1
      if(count == len(data)):
         count = 1
 
def check(data):
   count=0
   while(count<len(data)-1):
      if(data[count].replay_age()>data[count+1].replay_age()):
         return True
      count += 1
   return False
     
def count_age_low30(data):
   result = 0
   count  = 0
   while(count<len(data)):
      if(find_age_low30(data[count].replay_age())):
         result +=1
      count += 1
   return result
     
     
def find_age_low30(data):
   if(data<30):
      return True
   else:
      return False
     

def find_everage_age(data):
   result = 0
   count  = 0
   while(count<len(data)):
      result = result + data[count].replay_age()
      count += 1
   result = result / len(data)
   return result

class data_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 display(self):
      print(".......................")
      print("ID IS ",self.iD)
      print("name  ",self.name)
      print("age   ",self.age)
      print("weight",self.weight)
      print("height",self.height)
     
   def replay_age(self):
      return self.age
 
   def replay_id(self):
      return self.iD
 
   def replay_name(self):
      return self.name
 
   def replay_weight(self):
      return self.weight
 
   def replay_height(self):
      return self.height
 
   def get_id(self,iD):
      self.iD = iD
     
   def get_name(self,name):
      self.name = name
   
   def get_age(self,age):
      self.age = age
     
   def get_weight(self,weight):
      self.weight = weight
     
   def get_height(self,height):
      self.height = height  
     
     
     
     
   
             
 
   
   
 
 
setup()


Everage age is  8.5
Have student age low 30 about 4
.......................
ID IS  103
name   D
age    4
weight 70
height 160
.......................
ID IS  101
name   B
age    5
weight 56
height 162
.......................
ID IS  100
name   A
age    10
weight 80
height 160
.......................
ID IS  102
name   C
age    15
weight 96
height 182

วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2558

LAB 7 BMI if more print

def setup():
    A = data_student("A",100,15,80,160)
    B = data_student("B",101,18,56,162)
    C = data_student("C",102,28,96,182)
    data = [A,B,C]
    count = 0
    while(count<len(data)):
         if(find_student_BMI25(data[count].find_bmi())):
            data[count].display()
         count += 1
     
 
def find_student_BMI25(bmi):
   if(bmi>25):
      return True
   else:
      return False




class data_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 display(self):
      print(".......................")
      print("ID IS ",self.iD)
      print("name  ",self.name)
      print("age   ",self.age)
      print("weight",self.weight)
      print("height",self.height)
   
   def find_bmi(self):
      self.bmi = self.weight/((self.height/100)**2)
      return self.bmi
 
setup()

.......................
ID IS  100
name   A
age    15
weight 80
height 160
.......................
ID IS  102
name   C
age    28
weight 96
height 182


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

LAB 7 Show data + creat class

def setup():
   a = student("hydya",10164,30,150)
   b = student("ameba",10165,35,160)
   c = student("tic",10166,40,170)
   d = student("toc",10167,50,160)
   data_student = [a,b,c,d]
   display_array(data_student)

def display_array(data):
   count = 0
   while(count<len(data)):
      data[count].show_data()
      count += 1
 
 
class student:
   def __init__(self,name,iD,weight,height):
      self.name = name
      self.iD   = iD
      self.weight = weight
      self.height = height
 
   def show_data(self):
      print(">>>>>>>>>><<<<<<<<<<<<")
      print("Student name ",self.name)
      print("    id    is ",self.iD)
      print("weight is ",self.weight)
      print("height  is ",self.height)
 
setup()

ผลลัพธ์

>>>>>>>>>><<<<<<<<<<<<
Student name  hydya
    id    is  10164
weight is  30
height  is  150
>>>>>>>>>><<<<<<<<<<<<
Student name  ameba
    id    is  10165
weight is  35
height  is  160
>>>>>>>>>><<<<<<<<<<<<
Student name  tic
    id    is  10166
weight is  40
height  is  170
>>>>>>>>>><<<<<<<<<<<<
Student name  toc
    id    is  10167
weight is  50
height  is  160

วันเสาร์ที่ 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

LAB 6 Word

def setup():
   display_word(show_word(['A','E','C']))
   display_word(show_word(['A','B','C']))
   display_word(show_word(['B','E','C']))
 
def setKey(key):
   row_1_A = "    a    "
   row_2_A = "   a a   "
   row_3_A = "  a   a  "
   row_4_A = " a  a  a "
   row_5_A = "a       a"
   key_A   = [row_1_A,row_2_A,row_3_A,row_4_A,row_5_A]
   row_1_E = "eeeeeeee"
   row_2_E = "ee           "
   row_3_E = "eeeeeeee"
   row_4_E = "ee           "
   row_5_E = "eeeeeeee"
   key_E   = [row_1_E,row_2_E,row_3_E,row_4_E,row_5_E]
   row_1_C = " ccccccc"
   row_2_C = "ccc        "
   row_3_C = "cc          "
   row_4_C = "ccc        "
   row_5_C = " ccccccc"
   key_C   = [row_1_C,row_2_C,row_3_C,row_4_C,row_5_C]
   row_1_B = "bbbbbbb "
   row_2_B = "b      b     "
   row_3_B = "bbbbbbb "
   row_4_B = "b      b     "
   row_5_B = "bbbbbbb "
   key_B   = [row_1_B,row_2_B,row_3_B,row_4_B,row_5_B]
   if(key == 'A'):
      return key_A
   elif(key == 'B'):
      return key_B
   elif(key == 'C'):
      return key_C
   elif(key == 'E'):
      return key_E
   else:
     return ["","","","",""]

def show_word(input_key):
   output = ["","","","",""]
   count  = 0
   while(count < len(input_key)):
      count_row = 0
      while(count_row<len(output)):
         output[count_row] = output[count_row] + "  " + str(setKey(input_key[count])[count_row])
         count_row = count_row +1
      count = count + 1
   return output

def display_word(word):
   count_row = 0
   print("..................................")
   while(count_row<len(word)):
      print(word[count_row])
      count_row = count_row + 1

setup()


ผลลัพธ์

..................................
      a      eeeeeeee   ccccccc
     a a     ee        ccc     
    a   a    eeeeeeee  cc      
   a  a  a   ee        ccc     
  a       a  eeeeeeee   ccccccc
..................................
      a      bbbbbbb    ccccccc
     a a     b      b  ccc     
    a   a    bbbbbbb   cc      
   a  a  a   b      b  ccc     
  a       a  bbbbbbb    ccccccc
..................................
  bbbbbbb   eeeeeeee   ccccccc
  b      b  ee        ccc     
  bbbbbbb   eeeeeeee  cc      
  b      b  ee        ccc     
  bbbbbbb   eeeeeeee   ccccccc

LAB 6 Transpose

def setup():
   matrix_one = [[1,2,3],[4,5,6],[7,8,9]]
   print("before",matrix_one)
   print("after ",transpose(matrix_one))
 
 
def transpose(matrix):
   backup_value = 0
   count_colum = 0
   while(count_colum < len(matrix[0])):
      j = count_colum
      i = 0
      backup_value = matrix[i][j]
      matrix[i][j] = matrix[j][i]
      matrix[j][i] = backup_value
      count_colum  = count_colum + 1
   count_row = 1
   while(count_row < len(matrix)):
      i = count_row
      j = len(matrix[0])-1
      backup_value = matrix[i][j]
      matrix[i][j] = matrix[j][i]
      matrix[j][i] = backup_value
      count_row    = count_row + 1
   return matrix
 
setup()

before [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
after  [[1, 4, 7], [2, 5, 8], [3, 6, 9]]

LAB 6 Matrix

def setup():
   matrix_one = [[10,20],[15,15]] # row 1 and row 2
   matrix_two = [[15,15],[10,20]] # row 1 and row 2
   display(matrix_one)
   print (",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,")
   display(add_two_matrix(matrix_one,matrix_two))
   print (",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,")
   display(subtract_two_matrix(matrix_one,matrix_two))
   print ("......................................")
   display(multiply_two_matrix(matrix_one,matrix_two))
   print ("''''''''''''''''''''''''''''''''''''''")





def display(matrix):
   count_matrix = 0
   matrix = sort(matrix)
   while ( count_matrix < len(matrix)):
      print (matrix[count_matrix])
      count_matrix = count_matrix +1

def sort(matrix):
   count = 0
   result = make_zero_slot(matrix)
   count_result = 0
   while(count_result<len(result)):
      result[count_result] = make_zero_slot(matrix[0])
      count_result = count_result +1
   while(count < len(matrix)):
      count_sub = 0
      while(count_sub<len(matrix[count])):
         result[count][count_sub] =  matrix[count][count_sub]
         count_sub = count_sub + 1
      count = count +1
   return result

def add_two_matrix(matrix_one,matrix_two): #return after sort matrix
   new_matrix_after_add = [[],[]]
   count_matrix = 0                                # index of them
   while(count_matrix < len(matrix_one)):
      count_sub_matrix = 0                         # sub index
      while(count_sub_matrix < len(matrix_one[count_matrix])):
            new_matrix_after_add[count_matrix] = new_matrix_after_add[count_matrix]+[matrix_one[count_matrix][count_sub_matrix] + matrix_two[count_matrix][count_sub_matrix]]
            count_sub_matrix = count_sub_matrix +1
      count_matrix = count_matrix + 1
   return new_matrix_after_add

def subtract_two_matrix(matrix_one,matrix_two): #return after sort matrix
   new_matrix_after_subtract = [[],[]]
   count_matrix = 0                                # index of them
   while(count_matrix < len(matrix_one)):
      count_sub_matrix = 0                         # sub index
      while(count_sub_matrix < len(matrix_one[count_matrix])):
            new_matrix_after_subtract[count_matrix] = new_matrix_after_subtract[count_matrix]+[matrix_one[count_matrix][count_sub_matrix] - matrix_two[count_matrix][count_sub_matrix]]
            count_sub_matrix = count_sub_matrix +1
      count_matrix = count_matrix + 1
   return new_matrix_after_subtract

def multiply_two_matrix(matrix_one,matrix_two):
   if(len(matrix_one)==len(matrix_two)):
      result = make_zero_slot(matrix_one)
      count_result = 0
      while(count_result<len(result)):
         result[count_result] = make_zero_slot(matrix_two[0])
         count_result = count_result +1
      count_row_one = 0
      while(count_row_one < len(matrix_one)):
         count_colum_two = 0
         while(count_colum_two < len(matrix_two[0])):
               count_colum_one = 0
               sumRow = 0
               while(count_colum_one < len(matrix_one[count_row_one])):
                   sumRow = sumRow + matrix_one[count_row_one][count_colum_one]*matrix_two[count_colum_one][count_colum_two]
                   count_colum_one = count_colum_one +1
               result[count_row_one][count_colum_two] =  sumRow
               count_colum_two = count_colum_two +1
         count_row_one = count_row_one +1
      return result
   else:
      return "can't do that"
 
def make_zero_slot(matrix):
   result = []
   count_colum = 0
   while(count_colum < len(matrix)):
      result = result + ["0"]
      count_colum = count_colum + 1
   return result


setup()

ผลลัพธ์
[10, 20]
[15, 15]
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
[25, 35]
[25, 35]
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
[-5, 5]
[5, -5]
......................................
[350, 550]
[375, 525]
''''''''''''''''''''''''''''''''''''''

วันศุกร์ที่ 23 ตุลาคม พ.ศ. 2558

LAB 6 About 2D array and chair

def setup():
   chair_floor_one = [40,40,40,10,40]
   chair_floor_two = [20,30,50,80,70,120]
   chair_floor_three = [120,10,10]
   chair_in_building = [chair_floor_one,chair_floor_two,chair_floor_three]
   assert (find_total_chair_in_building(chair_in_building) == 680)
   print ("ALL Chair in this building is ",find_total_chair_in_building(chair_in_building))
   assert (find_floor_maxinum_chair(chair_in_building) == 1)
   print ("Index floor with maxinum chair is " ,find_floor_maxinum_chair(chair_in_building))
   assert (find_maxinum_chair(chair_in_building) == 120)
   find_room_and_floor_maxinum_chair(chair_in_building)
   
   
def find_total_chair_in_building(chair_in_building):
   count_floor = 0
   sumChair = 0
   while (count_floor < len(chair_in_building)):
      count_index_room = 0
      while(count_index_room < len(chair_in_building[count_floor])):
         sumChair = sumChair + chair_in_building[count_floor][count_index_room]
         count_index_room = count_index_room + 1
      count_floor = count_floor + 1
   return sumChair

def count_chair_floor(floor):
   result = 0
   count  = 0
   while(count < len(floor)):
      result = result + floor[count]
      count = count + 1
   return result

def find_floor_maxinum_chair(chair_in_building):
   count  = 0
   result = 0
   maxinum = count_chair_floor(chair_in_building[0])
   while(count < len(chair_in_building)):
      if(maxinum < count_chair_floor(chair_in_building[count])):
         maxinum = count_chair_floor(chair_in_building[count])
         result = count
      count = count + 1
   return result

def find_maxinum_chair(chair_in_building):
   result = 0
   count_floor = 0
   while(count_floor<len(chair_in_building)):
      count_room = 0
      while(count_room<len(chair_in_building[count_floor])):
         if(result < chair_in_building[count_floor][count_room]):
            result = chair_in_building[count_floor][count_room]
         count_room = count_room +1
      count_floor = count_floor +1
   return result

def find_room_and_floor_maxinum_chair(chair_in_building):
   count_floor = 0
   while(count_floor<len(chair_in_building)):
      count_room = 0
      while(count_room<len(chair_in_building[count_floor])):
         if(chair_in_building[count_floor][count_room] == find_maxinum_chair(chair_in_building)):
            print ("........found Room which maxinum chair is...........")
            print ("Floor index  is ",count_floor)
            print ("index  Room  is ",count_room)
            print ("number Chair is ",find_maxinum_chair(chair_in_building))
         count_room = count_room +1
      count_floor = count_floor +1
      
            
      
setup()   
   
   
   


   
   
   
   
   
   
 
 
 
ผลลัพธ์

ALL Chair in this building is  680
Index floor with maxinum chair is  1
........found Room which maxinum chair is...........
Floor index  is  1
index  Room  is  5
number Chair is  120
........found Room which maxinum chair is...........
Floor index  is  2
index  Room  is  0
number Chair is  120
 
 

วันพฤหัสบดีที่ 22 ตุลาคม พ.ศ. 2558

LAB 6 About weight

def setup():
   name = ['fizz','talon','vayny','darious']
   iD   = [10161,10164,10163,10054]
   age  = [10,20,30,20]
   weight = [ 30 , 40 ,50 ,80]
   height = [180 , 190 ,140,120 ]
   assert (find_minimum_weight(weight)==30)
   assert (find_number_weight_low50(weight)==[0,1])
   display_weight_low50(name,iD,age,weight,height)
 
def find_minimum_weight(weight):
   result = weight[0]
   count  = 0
   while(count < len(weight)):
      if(weight[count] < result):
         result = weight[count]
      count = count + 1
   return result

def find_number_weight_low50(weight):
   indexLow = []
   count = 0
   while ( count < len(weight)):
      if(weight[count] < 50 ):
         indexLow = indexLow + [count]
      count = count + 1
   return indexLow

def display_weight_low50(name,iD,age,weight,height):
   indexLow = find_number_weight_low50(weight)
   count    = 0
   while(count < len(indexLow)):
         print ("###########################")
         print ("ID . ",iD[indexLow[count]])
         print ("name   is ",name[indexLow[count]])
         print ("age    is ",age[indexLow[count]])
         print ("weight is ",weight[indexLow[count]])
         print ("hight  is ",height[indexLow[count]])
         count = count + 1

setup()

ผลลัพธ์
###########################
ID .  10161
name   is  fizz
age    is  10
weight is  30
hight  is  180
###########################
ID .  10164
name   is  talon
age    is  20
weight is  40
hight  is  190

วันจันทร์ที่ 19 ตุลาคม พ.ศ. 2558

LAB 6 About BMI

def setup():
   name = ['fizz','talon','vayny','darious']
   iD   = [10161,10164,10163,10054]
   age  = [10,20,30,20]
   weight = [ 70 , 60 ,50 ,80]
   hight = [180 , 190 ,140,120 ]
   assert (count_numberBMI_more25(weight,hight)==2)
   display_student_BMImore25(weight,hight,name,iD,age)

def findBMI(weight,hight):
   BMI = weight / ((hight/100)*(hight/100))
   return BMI

def count_numberBMI_more25(weight,hight):
   i = 0
   count = 0
   while(i<len(weight)):
      if (findBMI(weight[i],hight[i])>25):
         count = count + 1
      i = i + 1
   return count

def display_student_BMImore25(weight,hight,name,iD,age):
   i = 0
   while(i < len (name)):
      if(findBMI(weight[i],hight[i])> 25):
         print ("###########################")
         print ("ID . ",iD[i])
         print ("name   is ",name[i])
         print ("age    is ",age[i])
         print ("weight is ",weight[i])
         print ("hight  is ",hight[i])
      i = i +1
 
setup()



###########################
ID .  10163
name   is  vayny
age    is  30
weight is  50
hight  is  140
###########################
ID .  10054
name   is  darious
age    is  20
weight is  80
hight  is  120

LAB 6 Display student records

def setup():
   name = ['fizz','talon','vayny']
   iD   = [10161,10164,10163]
   age  = [10,20,30]
   weight = [ 70 , 60 ,50 ]
   hight = [180 , 190 ,140 ]
   displayStudentRecords(name,iD,age,weight,hight)

def displayStudentRecords(name,iD,age,weight,hight):
   i  = 0
   while ( i < len(name)):
      print ("###########################")
      print ("ID . ",iD[i])
      print ("name   is ",name[i])
      print ("age    is ",age[i])
      print ("weight is ",weight[i])
      print ("hight  is ",hight[i])

      i= i+1
setup()
   


###########################
ID .  10161
name   is  fizz
age    is  10
weight is  70
hight  is  180
###########################
ID .  10164
name   is  talon
age    is  20
weight is  60
hight  is  190
###########################
ID .  10163
name   is  vayny
age    is  30
weight is  50
hight  is  140

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

LAB 5 My_replace

def my_replace(string,getout,replace):
   result = ""
   i = 0
   while( i < len(string) ):
      if(check(getout,string,i)):
         result = result + replace
         i = i +len(replace)
      else:
         result = result + string[i]
         i = i +1
   return result
   
def check(getout,string,i):
   count =1
   while(count<len(getout)):
      if(getout[count]!=string[i]):
         return False
      else:
         count = count+1
         i = i+1
   return True



assert (my_replace("ThaiLand","Land","Joke")=="ThaiJoke")
print (my_replace("ThaiLand","Land","Joke"))
 


ThaiJoke