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

lab 7 display BMI

def setup():
    a = student("Giggs",20,180,60)
    b = student("Keane",18,165,90)
    c = student("Cole",21,185,74)
    d = student("Scholes",19,177,55)
    e = student("Park",18,175,46)
    a.show()
    b.show()
    c.show()
    d.show()
    e.show()
    print('BMI of',a.get_name(),calculation_of_bmi(a))
    print('BMI of',b.get_name(),calculation_of_bmi(b))
    print('BMI of',c.get_name(),calculation_of_bmi(c))
    print('BMI of',d.get_name(),calculation_of_bmi(d))
    print('BMI of',e.get_name(),calculation_of_bmi(e))
   
def calculation_of_bmi(student):
    highM = student.get_high()/100
    bmi = student.get_weight()/(highM*highM)
    return bmi
class student:

    def __init__(self,name,age,high,weight):
        self.name = name
        self.age = age
        self.weight = weight
        self.high = high
    def show(self):
        print(self.name, end = "  ")
        print(self.age, end = "  ")
        print(self.weight, end = "  ")
        print(self.high, end = "  ")
        print()
    def get_weight(self):
        return self.weight
    def get_high(self):
        return self.high      
    def get_name(self):
        return self.name      
setup()      
   
 
 
 
 
 
 
 
 
 
 
 
 

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

lab 7 display name age weight and high

def setup():
    a = student("Giggs",20,180,60)
    b = student("Keane",18,165,90)
    c = student("Cole",21,185,74)
    d = student("Scholes",19,177,55)
    e = student("Park",18,175,46)
    a.show()
    b.show()
    c.show()
    d.show()
    e.show()
class student:

    def __init__(self,name,age,weight,high):
        self.name = name
        self.age = age
        self.weight = weight
        self.high = high
    def show(self):
        print(self.name, end = "  ")
        print(self.age, end = "  ")
        print(self.weight, end = "  ")
        print(self.high, end = "  ")
        print()  
setup()      

lab 6 sort age

def setup():
    age = [35,19,18,20,19,31]
    print(age)
    print('Display the age that less than 30 years old by sort age')
    sort_age(age)
    show_age(age)
   
def show_age(age):
        count = 0
        find_age = 30
        while(count<len(age)):
            if(age[count]<find_age):
               print(age[count])
            count = count + 1
def sort_age(age):
        index =1
        while(index<len(age)):
            new_age =age[index]
            index2=index
            while(index2>0 and age[index2-1]>new_age):
                age[index2]=age[index2-1]
                index2=index2-1
            age[index2]=new_age
            index=index+1
setup()

lab 6 multiply

def setup():
   row_11=[20,15]
   row_12=[37,3]
   matrix1=[row_11,row_12]
   row_21=[4,16]
   row_22=[51,34]
   matrix2=[row_21,row_22]
   multiply_matrix(matrix1,matrix2)
def multiply_matrix(matrix1,matrix2):
   index=0
   index2=0
   k=0
   add1=0
   add2=0
   multiply=0
   while(index<len(matrix1)):
      print("|",end=" ")
      while(index2<len(matrix1)):
         add1 = matrix1[index][k]*matrix2[k][index2]
         add2 = matrix1[index][k+1]*matrix2[k+1][index2]
         multiply = add1+add2
         print(multiply,end=" ")
         index2 = index2 + 1
      index2 = 0
      print("|")
      index = index+1
   
setup()

lab 6 find chairs

def setup():
    floor_one = [10,25,30,55]
    floor_two = [25,65,20,30]
    floor_three = [15,25,40,45]
    building = [floor_one,floor_two,floor_three]
    print('Floor one has',totol_chairs(floor_one),'chairs')
    print('Floor two has',totol_chairs(floor_two),'chairs')
    print('floor three has',totol_chairs(floor_three),'chairs')
    print('Total chairs are',total_chairs(building))
    print('The number of maximum Chairs are in floor',max_floor(building))
    print('The class that have maximum chairs is',find_max_class(building),'chairs')
def totol_chairs(floor_one):
    index = 0
    sum= 0
    while(index < len(floor_one)):
        sum += floor_one[index]
        index += 1
    return sum
def totol_chairs(floor_two):
    index = 0
    sum= 0
    while(index < len(floor_two)):
        sum += floor_two[index]
        index += 1
    return sum
def totol_chairs(floor_three):
    index = 0
    sum= 0
    while(index < len(floor_three)):
        sum += floor_three[index]
        index += 1
    return sum
def total_chairs(building):
    allchairs = 0
    index = 0
    while(index<len(building)):
        j = 0
        while(j<len(building[index])):
            allchairs = allchairs + building[index][j]
            j = j + 1
        index = index + 1
    return allchairs
def max_floor(building):
    max_floor = 0
    index = 0
    while(index<len(building)):
        summation = 0
        j = 0
        while(j<len(building[index])):
            summation = summation + building[index][j]
            j = j + 1
        if(summation>max_floor):
            max_floor = index
        index = index + 1
    return max_floor
def find_max_class(building):
    maximum = 0
    index = 0
    while(index < len(building)):
        j = 0
        while(j < len(building[index])):
            if(building[index][j] > maximum):
               maximum = building[index][j]
            j = j + 1
        index = index + 1
    return maximum
setup()                              

lab 6 transpose

def setup():
   row_11 = [20,15]
   row_12 = [37,3]
   matrix = [row_11,row_12]
   transpose(matrix)
def transpose(matrix):
   index=0
   index2=0
   while(index<len(matrix)):
      print("|",end=" ")
      while(index2<len(matrix[index])):
         print(matrix[index2][index],end=" ")
         index2 = index2 +1
      index2 = 0
      print("|")
      index = index +1
   
setup()

lab 6 subtract

def setup():
   row_11=[20,15]
   row_12=[37,3]
   matrix1=[row_11,row_12]
   row_21=[4,16]
   row_22=[51,34]
   matrix2=[row_21,row_22]
   new_matrix(matrix1,matrix2)
 
def new_matrix(matrix1,matrix2):
   index =0
   index2 =0
   result=0
 
   while(index<len(matrix1)):
      print("|",end=" ")
      while(index2<len(matrix1)):
         result = matrix1[index][index2]-matrix2[index][index2]
         print(result ,end=" ")
         index2=index2+1
      index2=0
      print("|")
      index=index+1
   
setup()

lab 6 add matrix

def setup():
   row_11=[20,15]
   row_12=[37,3]
   matrix1=[row_11,row_12]
   row_21=[4,16]
   row_22=[51,34]
   matrix2=[row_21,row_22]
   new_matrix(matrix1,matrix2)
 
def new_matrix(matrix1,matrix2):
   index=0
   index2=0
   result=0
 
   while(index<len(matrix1)):
      print("|",end=" ")
      while(index2<len(matrix1)):
         result = matrix1[index][index2]+matrix2[index][index2]
         print(result ,end=" ")
         index2=index2+1
      index2=0
      print("|")
      index=index+1
   
setup()

lab 6 display matrix

def setup():
   row_11=[20,15]
   row_12=[37,3]
   matrix=[row_11,row_12]
   show_matrix(matrix1)
 
def show_matrix(matrix):
   index=0
   index2=0
   while(index<len(matrix)):
      print("|",end=" ")
      while(index2<len(matrix[index])):
         print(matrix[index][index2],end=" ")
         index2=index2+1
      index2=0
      print("|")
      index=index+1
setup()

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

lab 6 ILT

def setup():
    print('    ########  ##########    ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('          ##                ##            ##')
    print('    ########          ##            #######')
setup()
   

lab 6 display age

def setup():
    age = [35,19,18,20,19,31]
    print(age)
    print('Display the age that less than 30 years old')
    show_age(age)
def show_age(age):
        count = 0
        find_age = 30
        while(count<len(age)):
            if(age[count]<find_age):
               print(age[count])
            count = count + 1
setup()

lab 6 count age

def setup():
    student_number = [1,2,3,4,5,6]
    age = [35,19,18,20,19,31]
    high = [177,182,170,169,185,160]
    weight = [65,50,60,75,80,55]
    data = [student_number,age,high,weight]
    print(find_the_age(age),'students have age under 30 years old')
def find_the_age(age):
        count = 0
        count_age = 30
        find_age = 0
        while(count<len(age)):
            if(age[count]<count_age):
              find_age +=1
            count = count + 1
        return find_age

   
setup()  

lab 6 find display and count bmi

def setup():
    name = ["Keane","Giggs","Cole","Scholes","Park","Nani"]
    student_number = [1,2,3,4,5,6]
    age = [35,19,18,20,19,31]
    high = [177,182,170,169,185,160]
    weight = [95,50,90,75,60,48]
    data = [student_number,age,high,weight,name]
    find_bmi(student_number,name,weight,high)
    print('There are',count_bmi(student_number,name,weight,high),'students that have BMI more than 25')
def find_bmi(student_number,name,weight,high):
        index = 0
        bmi = 0
        count = 0
        while(index<len(student_number)):
            bmi = weight[count]/((high[count]/100)*2)
            count  = count + 1
            print('BMI of ',name[index],bmi)
            index = index + 1
def count_bmi(student_number,name,weight,high):
        index = 0
        bmi = 0
        count = 0
        while(index<len(student_number)):
            bmi = weight[index]/((high[index]/100)*2)
            if(bmi>25):
                count += 1
            index = index + 1
        return count
                           
setup()

lab 6 display weight that less than 50 kg.

def setup():
    weight = [95,50,90,75,60,48]
    print('Display weight that under 50  kg.')
    find_weight(weight)
def find_weight(weight):
    count = 0
    find_weight = 50
    while(count<len(weight)):
        if(weight[count]<find_weight):
          print(weight[count])
        count = count + 1

setup()        

lab 6 display number of student that have weight less than 50

def setup():
    weight = [95,50,90,75,60,48]
    print(find_weight(weight),'students have weight less than 50 kg.')
def find_weight(weight):
    count = 0
    find_weight = 50
    count_weight = 0
    while(count<len(weight)):
        if(weight[count]<find_weight):
          count_weight +=1
        count = count + 1
    return count_weight
setup()        

lab 6 student data Average age and minimum weight

def setup():
    name = ["Keane","Giggs","Cole","Scholes","Park","Nani"]
    student_number = [1,2,3,4,5,6]
    age = [35,19,18,20,19,31]
    high = [177,182,170,169,185,160]
    weight = [95,50,90,75,60,48]
    data = [student_number,age,high,weight,name]
    print('Student name     ',data[4][0])
    print('Student number ',data[0][0])
    print('Age            ',data[1][0],'years old')
    print('High           ',data[2][0],'cm.')
    print('Weight         ',data[3][0],'kg.')
    print('Student name     ',data[4][1])
    print('Student number ',data[0][1])
    print('Age            ',data[1][1],'years old')
    print('High           ',data[2][1],'cm.')
    print('Weight         ',data[3][1],'kg.')
    print('Student name     ',data[4][2])
    print('Student number ',data[0][2])
    print('Age            ',data[1][2],'years old')
    print('High           ',data[2][2],'cm.')
    print('Weight         ',data[3][2],'kg.')
    print('Student name     ',data[4][3])
    print('Student number ',data[0][3])
    print('Age            ',data[1][3],'years old')
    print('High           ',data[2][3],'cm.')
    print('Weight         ',data[3][3],'kg.')
    print('Student name     ',data[4][4])
    print('Student number ',data[0][4])
    print('Age            ',data[1][4],'years old')
    print('High           ',data[2][4],'cm.')
    print('Weight         ',data[3][4],'kg.')
    print('Student name     ',data[4][5])
    print('Student number ',data[0][5])
    print('Age            ',data[1][5],'years old')
    print('High           ',data[2][5],'cm.')
    print('Weight         ',data[3][5],'kg.')
    print('Average age',(age[0]+age[1]+age[2]+age[3]+age[4]+age[5])/4,'Years old')
    print('The minimum weight is',find_minimum_weight(weight),'kg.')
def find_minimum_weight(weight):
    count = 0
    minimum = 100
    while(count < len(weight)):
        if(weight[count] < minimum):
            minimum = weight[count]
        count = count + 1
    return minimum

setup()