วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558

lab in class room

class Person:
   def __init__(self,name,age,weight,height):
      self.name = name
      self.age = age
      self.weight = weight
      self.height = height
     
   def get_name(self):
      return self.name
 
   def get_age(self):
      return self.age
 
   def get_weight(self):
      return self.weight
 
   def get_height(self):
      return self.height
 
class Student(Person):
   def __init__(self,name,age,weight,height,student_id):
      super().__init__(name,age,weight,height)
      self.student_id = student_id
     
   def get_student_id(self):
      return self.student_id
 
def find_bmi(data_person):
   bmi = data_person.get_weight()/(((data_person.get_height())/100)*((data_person.get_height())/100))
   print( bmi )
 
 
def main():
   a = Student("X","1",50,150,"111")
   b = Person ("S","12",60,170)
   c = Student("Y","2",55,155,"112")
   data_student  = [ a,c ]
   print (a.get_age())
   print (a.get_student_id())
   print (b.get_age())
   print (data_student[1].get_age())
   print (data_student[1].get_student_id())
   find_bmi(a)
 
main()

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

LAB 8 BANNER uncom

public class set {
    public String row1;
    public String row2;
    public String row3;
    public String row4;
    public String row5;
    static String X = "+";
    public String data_import;
    public set(String data){
        check(data);
        data_import = data;

    }
   
    public void check(String data){
        if(null != data)switch (data) {
            case "A":
                row1 = "     "+X+"     ";
                row2 = "    "+X+" "+X+"    ";
                row3 = "   "+X+" "+X+" "+X+"   ";
                row4 = "  "+X+"     "+X+"  ";
                row5 = " "+X+"       "+X+" ";
                break;
            case "B":
                row1 = " "+X+" "+X+" "+X+" "+X+"  ";
                row2 = " "+X+"      "+X+" ";
                row3 = " "+X+" "+X+" "+X+" "+X+"  ";
                row4 = " "+X+"      "+X+" ";
                row5 = " "+X+" "+X+" "+X+" "+X+"  ";
                break;
            case "C":
                row1 = "  "+X+X+X+X+X+X+X+" ";
                row2 = " "+X+"        ";
                row3 = " "+X+"        ";
                row4 = " "+X+"        ";
                row5 = "  "+X+X+X+X+X+X+X+" ";
                break;
            default:
                row1 = "         ";
                row2 = "         ";
                row3 = "         ";
                row4 = "         ";
                row5 = "         ";
                break;
        }    
    }
   
    public String get_row(int row){
        if(0 != row)switch (row) {
            case 1:
                return row1;

            case 2:
                return row2;

            case 3:
                return row3;

            case 4:
                return row4;

            case 5:
                return row5;

        }
        return "";
    }
   
    public void get_char_srting(String char_){
        X = char_;
    }
   
    public String get_data_import(){
    return data_import;
}
}



public class main {
    public static void main(String[] args){
        set[] data = {new set("A"),new set("B"),new set("C")};
        display(data);
        set_char(data,"x");
        display(data);
       
    }
   
    public static void display(set[] data){
        int count_char = 0;
        while(count_char<6){
            int count = 0;
            while(count<3){
                System.out.print(data[count].get_row(count_char));
                count +=1;
            }
            count_char +=1;
            System.out.println("");
        }
    }
   
    public static void set_char(set[] data,String char_){
        int count_char = 0;
        while(count_char<data.length){
            data[count_char].get_char_srting(char_);
            data[count_char] = new set(data[count_char].get_data_import());
            count_char +=1;
        }
    }

   }


ผลลัพธ์

      +      + + + +      +++++++
    + +     +      +     +      
   + + +   + + + +   +      
  +     +   +      +     +      
 +       +  + + + +     +++++++

      x      x x x x     xxxxxxx
    x x     x      x    x      
   x x x   x x x x   x      
  x     x   x      x    x      
 x       x  x x x x     xxxxxxx

LAB 8 WEIGHT

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    public int bmi;
    static int count;
 
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    bmi    =  weight/((height/100)^2);
    count +=1;
    }
 
    public int get_age(){
        return age;
    }
 
    public int get_wei(){
        return weight;
    }
 
    public int get_hei(){
        return height;
    }
 
    public int get_id(){
        return id;
    }
 
    public String get_name(){
        return name;
    }
 
   
 
    public void display_name(){
        System.out.println ("Name is "+name);
    }
 
    public void display_age(){
        System.out.println ("Age is "+age);
    }
 
    public void display_id(){
        System.out.println ("id is "+id);
    }
 
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
 
    public void display_height(){
        System.out.println ("height is " +height);
    }
 
    public void display_bmi(){
        System.out.println ("BMI is "+bmi);
    }
 
    public int get_count(){
        return count;
    }
 
 
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        display_bmi();
        System.out.println(" ");
    }
 

}


public class main {
    public static void main(String[] args) {
        data_student[] data = {new data_student("A",01,10,55,167),
                                      new data_student("B",02,16,98,165),
                                      new data_student("C",03,18,45,168),
                                      new data_student("D",04,17,80,150)};
       
        System.out.println ("count weight low 50 is "+count_weiL50(data));
        display_data(data);

       
    }
   
    public static int get_minimum(data_student[] data){
        int count =0;
        int result = 0;
        while(count<data.length){
            if(data[count].get_wei()>result){
                result = data[count].get_wei();
            }
            count += 1;
        }
        return result;
    }
   
    public static int count_weiL50(data_student[] data){
        int count =0;
        int result = 0;
        while(count<data.length){
            if(data[count].get_wei()<50){
                result +=1;
            }
            count +=1;
        }
        return result;
    }
   

   
    public static void display_data(data_student[] data){
        int count =0;
        while(count<data.length){
            if(data[count].get_wei()<50){
                data[count].display_data();
        }
        count +=1;
        }
    }
}

ผลลัพธ์

count weight low 50 is 1
Name is C
id is 3
Age is 18
weight is 45
height is 168
BMI is 15

LAB 8 AGE

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    public int bmi;
    static int count;
   
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    bmi    =  weight/((height/100)^2);
    count +=1;
    }
   
    public int get_age(){
        return age;
    }
   
    public int get_wei(){
        return weight;
    }
   
    public int get_hei(){
        return height;
    }
   
    public int get_id(){
        return id;
    }
   
    public String get_name(){
        return name;
    }
   
     public void set_name(String name_){
        name = name_;
    }
   
     public void set_id(int id_){
        id = id_;
    }
   
     public void set_age(int age_){
        age = age_;
    }
   
     public void set_hei(int hei){
        height = hei;
    }
   
    public void set_wei(int wei){
        weight = wei;
    }
   
   
   
    public void display_name(){
        System.out.println ("Name is "+name);
    }
   
    public void display_age(){
        System.out.println ("Age is "+age);
    }
   
    public void display_id(){
        System.out.println ("id is "+id);
    }
   
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
   
    public void display_height(){
        System.out.println ("height is " +height);
    }
   
    public void display_bmi(){
        System.out.println ("BMI is "+bmi);
    }
   
    public int get_count(){
        return count;
    }
   
   
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        display_bmi();
        System.out.println(" ");
    }
   

}


public class main {
    public static void main(String[] args) {
        data_student[] data = {new data_student("A",01,10,55,167),
                                      new data_student("B",02,16,98,165),
                                      new data_student("C",03,18,65,168),
                                      new data_student("D",04,17,80,150)};
        System.out.print(find_everage(data));
        System.out.println(" ");
        sort(data);
        display_data(data);
       
    }
    public static int find_everage(data_student[] data){
        int sum_age = 0;
        int average;
        for(int count =0;count<(data.length);count+=1){
            sum_age += data[count].get_age();
        }
        average = sum_age/data.length;
        return average;
        }
   
    public static boolean check(data_student[] data){
        int count =0;
        while(count<(data.length)-1){
            if(data[count].get_age()>data[count+1].get_age()){
                return true;
            }
            count +=1;
        }
        return false;
    }
   
    public static void sort(data_student[] data){
        int count =1;
        while(check(data)){
            if(data[count].get_age()<data[count-1].get_age()){
                int backup_id = data[count].get_id();
                String backup_name = data[count].get_name();
                int backup_age = data[count].get_age();
                int backup_height = data[count].get_hei();
                int backup_weight = data[count].get_wei();
               
                data[count].set_id((data[count-1]).get_id());
                data[count].set_age((data[count-1]).get_age());
                data[count].set_name((data[count-1]).get_name());
                data[count].set_hei((data[count-1]).get_hei());
                data[count].set_wei((data[count-1]).get_wei());
               
                data[count-1].set_id(backup_id);
                data[count-1].set_age(backup_age);
                data[count-1].set_name(backup_name);
                data[count-1].set_hei(backup_height);
                data[count-1].set_wei(backup_weight);
               
            }
            count +=1;
            if(count == data.length){
                count =1;
            }
        }
    }
   
    public static void display_data(data_student[] data){
        int count = 0;
        while(count<data.length){
            data[count].display_data();
            count +=1;
        }
    }
}

ผลลัพธ์

run:


15
Name is A
id is 1
Age is 10
weight is 55
height is 167
BMI is 18

Name is B
id is 2
Age is 16
weight is 98
height is 165
BMI is 32

Name is D
id is 4
Age is 17
weight is 80
height is 150
BMI is 21

Name is C
id is 3
Age is 18
weight is 65
height is 168
BMI is 26

BUILD SUCCESSFUL (total time: 0 seconds)


วันอาทิตย์ที่ 8 พฤศจิกายน พ.ศ. 2558

LAB Fraction

class fraction:
   def __init__(self,numberator,denominator=1):
      self.num = numberator
      self.deno = denominator
     
   def get_num(self):
      return self.num
 
   def get_deno(self):
      return self.deno
 
   def sum_fraction_number(self,b):
      return (self.num*b.get_deno())+(b.get_num()*self.deno)
     
   def sum_fraction_deno(self,b):
      return (self.deno*b.get_deno())
     
   def display(self):
      if(self.deno>0):
         print (self.num," / ",self.deno)
      else:
         print (" Can't be calculated ")
 
def setup():
   a = fraction(2,4)
   b = fraction(5,0)
   d = fraction(7,3)
   c = fraction((a.sum_fraction_number(d)),(a.sum_fraction_deno(b)))
   f = fraction((a.sum_fraction_number(d)),(a.sum_fraction_deno(d)))
   a.display()
   b.display()
   c.display()
   f.display()

 
 
setup()


ผลลัพธ์

2  /  4
 Can't be calculated 
 Can't be calculated 
34  /  12

LAB IN CLASS

class complex:
   def __init__(self,real,imag):
      self.real = real
      self.imag = imag
      self.valu_imag = self.imag*((-1)**0.5)
     
   def display(self):
      if(self.imag>0):
         print (self.real," + ",self.imag,"i")
      elif(self.imag<0):
         print (self.real," - ",(-1)*self.imag,"i")
      else:
         print (self.real)
     
   def get_real(self):
      return self.real
 
   def get_imag(self):
      return self.imag
     
   def add_real(self,obj):
      return self.real + obj.get_real()
 
   def add_imag(self,obj):
      return self.imag + obj.get_imag()
     
     

 
def setup():
   a = complex(1,2)
   b = complex(3,-4)
   a.display()
   c = complex(a.add_real(b),a.add_imag(b))
   c.display()
 
 
 
setup()

ผลลัพธ์

1  +  2 i
4  -  2 i

วันเสาร์ที่ 7 พฤศจิกายน พ.ศ. 2558

LAB 8 BMI

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    public int bmi;
   
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    bmi    =  weight/((height/100)^2);
    }
   
    public int get_bmi(){
        return bmi;
    }
   
    public void display_name(){
        System.out.println ("Name is "+name);
    }
   
    public void display_age(){
        System.out.println ("Age is "+age);
    }
   
    public void display_id(){
        System.out.println ("id is "+id);
    }
   
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
   
    public void display_height(){
        System.out.println ("height is " +height);
    }
   
    public void display_bmi(){
        System.out.println ("BMI is "+bmi);
    }
   
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        display_bmi();
        System.out.println(" ");
    }
   

}


public class main {
   
    public static void main(String[] args) {
        data_student[] data = {new data_student("A",01,10,55,167),
                               new data_student("B",02,16,98,165),
                               new data_student("C",03,18,65,168),
                               new data_student("D",04,17,80,150)};
       
        for(int count =0;count<data.length;count +=1){
            if(data[count].get_bmi()>25){
                data[count].display_data();
            }
        }
       
    }
   
}
       
       
ผลลัพ


Name is B
id is 2
Age is 16
weight is 98
height is 165
BMI is 32

Name is D
id is 4
Age is 17
weight is 80
height is 150
BMI is 26

LAB 8 JAVA.DISPLAY DATA

public class data_student {
    public String name;
    public int id ;
    public int age;
    public int weight;
    public int height;
    static int count=0;
   
   
    public data_student(String name_stu,int iD,int age_stu,int weight_stu,int height_stu){
    name = name_stu;
    id  = iD;
    age = age_stu;
    weight = weight_stu;
    height = height_stu;
    count +=1;
    }
   
    public void display_name(){
        System.out.println ("Name is "+name);
    }
   
    public void display_age(){
        System.out.println ("Age is "+age);
    }
   
    public void display_id(){
        System.out.println ("id is "+id);
    }
   
    public void display_weight(){
        System.out.println ("weight is "+weight);
    }
   
    public void display_height(){
        System.out.println ("height is " +height);
    }
   
    public void display_data(){
        display_name();
        display_id();
        display_age();
        display_weight();
        display_height();
        System.out.println(" ");
    }

}


public class main {
    static int[] main_data;
    public static void main(String[] args) {
        data_student a = new data_student("A",01,10,50,160);
        data_student b = new data_student("B",02,15,64,170);
        data_student c = new data_student("C",03,7,49,155);
       
        a.display_data();
        b.display_data();
        b.display_data();
       
    }

}


ผลลัพธ์

Name is A
id is 1
Age is 10
weight is 50
height is 160
 
Name is B
id is 2
Age is 15
weight is 64
height is 170
 
Name is B
id is 2
Age is 15
weight is 64
height is 170


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

REPORT RASPBERRY

สิ่งที่ได้เรียนรู้


    - เรียนรู้วิธีการใช้งาน Raspberry เบื้องต้น และใช้งาน python

ความรู้สึก

    - มันช้าไปหน่อย อืดๆ แต่ก็ น่าจะปรกติ เพราะ มันค่อนข้างเล็ก

   - เน็ท ช้ามาก ใช้เวลา ต่อเว็ปต่างๆนาน ทำให้เสียเวลา

lab raspberry

class student:
    def __init__(self,name,iD,score):
        self.name = name
        self.id = iD
        self.score = score

    def display_name(self):
        print('name is',self.name)

    def display_id(self):
        print('id is ',self.id)

    def display_score(self):
        print('score is',self.score)

    def display_all(self):
        print("...................")
        self.display_name()
        self.display_id()
        self.display_score()

    def get_score(self):
        return self.score

    def set_score(self):
        self.score = score


def getGrade(score):
     if(score >=80):
        return "A"
     elif(score >=70):
        return "B"
     elif(score >=60):
        return "C"
     elif(score >=50):
        return "D"
     else:
        return  "F"


       
def  count_grade(obj):
    A = 0
    B = 0
    C = 0
    D = 0
    F = 0
    count = 0
    while(count < len(obj)):
        if(getGrade(obj[count].get_score()) == "A"):
            A+= 1
        elif(getGrade(obj[count].get_score()) == 'B'):
            B += 1
        elif(getGrade(obj[count].get_score()) == 'C'):
            C += 1
        elif(getGrade(obj[count].get_score())== 'D'):
            D += 1
        elif(getGrade(obj[count].get_score())== 'F'):
            F += 1
        count +=1
    print("........................")
    print("have grade A" ,A ,"person")
    print("have grade B" ,B,"person")
    print("have grade C" ,C,"person")
    print("have grade D" ,D ,"person")
    print("have grade F" ,F, "person")
       
 
   
def show_all_grade(obj):
    count = 0
    while(count< len(obj)):
        obj[count].display_all()
        print("have grade",getGrade(obj[count].get_score()))
        count +=1

       
       
def setup():
    data_student = [ student('joker',1,80),
                     student('Mind',2,70),
                     student('Eiei',3,87),
                     student('Gigi',4,50),
                     student('Hihi',5,65)]
    show_all_grade(data_student)
    count_grade(data_student)
   
    print("student 1 have grade is",getGrade(data_student[0].get_score()))


setup()  
   
   
                           

วันอังคารที่ 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

วันพุธที่ 30 กันยายน พ.ศ. 2558

LAB 5 Find base 2 from base ten

def findBaseTwo(number):
   reverstBase=""
   result =""
   while(number>=1):
   
      intValue = str(int(number%2))
      if(number/2>0):
         reverstBase = reverstBase + intValue
      number = number /2
   
   count = 0
   while(count<len(reverstBase)):
      result = result + reverstBase[len(reverstBase)-count-1]
      count = count+1

   return result

print (findBaseTwo(30))
assert (findBaseTwo(30)=="11110")
print (findBaseTwo(300))
assert (findBaseTwo(300)=="100101100")


ผลลัพธ์
11110
100101100

วันอังคารที่ 29 กันยายน พ.ศ. 2558

LAB 5 my_startwith my_endwith

def setup():
   array = "overloader    Over"
   assert (my_startwith(array,"over"))
   print ("boolean of start with is",my_startwith(array,"over"))
   assert (my_endwith(array,"er"))
   print ("boolean of end with is",my_endwith(array,"er"))

def my_startwith(array,startWith):
   if(len(array)>=len(startWith)):
      i=0
      while(i<len(startWith)):
         if(array[i]==startWith[i]):
            i=i+1
         else:
            return False
      return True
 
def my_endwith(array,endWith):
   if(len(array)>=len(endWith)):
      i=len(array)-len(endWith)
      count = 0
      while(i<len(array)):
         if(array[i]==endWith[count]):
            i=i+1
            count=count+1
         else:
            return False
      return True
 
setup()  

ผลลัพธ์
boolean of start with is True
boolean of end with is True

LAB 5 Strip

def setup():
   array = "overloader    Over"
   print (my_strip(array))
   assert (my_strip(array)=="overloaderOver")



   
def my_strip(array):
   newArray = ""
   i = 0
   while(i<len(array)):
      if(array[i]!=" "):
         newArray = newArray + array[i]
      i=i+1
   return newArray


setup()  

ผลลัพธ์
overloaderOver

LAB 5 my_count my_find

def setup():
   array = "overloader"
   print ("value =",my_count(array,"e"))
   assert (my_count(array,"e")==2)
 
   print ("you fist index e is",my_find(array,"e"))
   assert (my_find(array,"e")==2)

def my_count(array,wantCount):
      i = 0
      count =0
      while(i < len(array)):
         if(array[i]==wantCount):
            count=count+1
         i=i+1
      return count
 
 
def my_find(array,wantFind):
   i = 0
   while(i<=len(array)):
      if(array[i] == wantFind):
         return i
      i=i+1
   return "."

   
 
   

setup()  


ผลลัพธ์
value = 2
you fist index e is 2

วันเสาร์ที่ 26 กันยายน พ.ศ. 2558

AS 1 VER1