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

[LAB6] Large Letter #2D_Array

def setup():
   my_word = input("")
   draw_word(my_word)
 
def draw_word(my_word):
   B_line0 = "##### "
   B_line1 = "#    #"
   B_line2 = "##### "
   B_line3 = "#    #"
   B_line4 = "##### "
   word_B = [B_line0,B_line1,B_line2,B_line3,B_line4]
   U_line0 = "#    #"
   U_line1 = "#    #"
   U_line2 = "#    #"
   U_line3 = "#    #"
   U_line4 = " #### "
   word_U = [U_line0,U_line1,U_line2,U_line3,U_line4]
   N_line0 = "#    #"
   N_line1 = "##   #"
   N_line2 = "# #  #"
   N_line3 = "#   ##"
   N_line4 = "#    #"
   word_N = [N_line0,B_line1,N_line2,N_line3,N_line4]
   G_line0 = " #### "
   G_line1 = "#     "
   G_line2 = "# ### "
   G_line3 = "#    #"
   G_line4 = "##### "
   word_G = [G_line0,G_line1,G_line2,G_line3,G_line4]
   i_print = 0
   while(i_print < len(word_G)):
      i = 0
      while(i < len(my_word)):
         if(my_word[i] == "B"):
            print(word_B[i_print],end = " ")
         elif(my_word[i] == "U"):
            print(word_U[i_print],end = " ")
         elif(my_word[i] == "N"):
            print(word_N[i_print],end = " ")
         elif(my_word[i] == "G"):
            print(word_G[i_print],end = " ")
         i = i + 1
      print("")
      i_print = i_print + 1
     
setup()

[LAB6] Matrix(+Transpose) #2D_Array

def setup():
   first1 = [1, 2, 3]
   second1 = [2, 4, 6]
   third1 = [3, 5, 7]
   maxtrix1 = [first1,second1,third1]
   third2 = [1, 2, 3]
   first2 = [2, 3, 6]
   second2 = [3, 5, 7]
   maxtrix2 = [first2,second2,third2]
   display(maxtrix1)
   display(maxtrix2)
   #add(maxtrix1,maxtrix2)
   #sub(maxtrix1,maxtrix2)
   #multi(maxtrix1,maxtrix2)
   print("///// Transpose /////")
   tran(maxtrix1)
   #display(maxtrix1)
 
def display(maxtrix1):
   h = 0
   while(h < len(maxtrix1)):
      v = 0
      print(end = "")
      while(v < len(maxtrix1[h])):
         print("",maxtrix1[h][v],"", end = "")
         v = v + 1
      print("")
      h = h + 1
   print("")

def add(maxtrix1,maxtrix2):
   h = 0
   while(h < len(maxtrix1)):
      v = 0
      print(end = "")
      while(v < len(maxtrix1[h])):
         print("",maxtrix1[h][v]+maxtrix2[h][v],"",end = "")
         v = v + 1
      print("")
      h = h + 1
   
def sub(maxtrix1,maxtrix2):
   h = 0
   while(h < len(maxtrix1)):
      v = 0
      print(end = "")
      while(v < len(maxtrix1[h])):
         print("",maxtrix1[h][v]-maxtrix2[h][v],"",end = "")
         v = v + 1
      print("")
      h = h + 1
   
def multi(maxtrix1,maxtrix2):
   h = 0
   while(h < len(maxtrix1)):
      v = 0
      print(end = "")
      while(v < len(maxtrix1[h])):
         print("",maxtrix1[h][v]*maxtrix2[h][v],"",end = "")
         v = v + 1
      print("")
      h = h + 1

def tran(maxtrix1):
   h = 0
   while(h < len(maxtrix1)):
      v = h
      while(v < len(maxtrix1[h])):
         charge = maxtrix1[h][v]
         maxtrix1[h][v] = maxtrix1[v][h]
         maxtrix1[v][h] = charge
         v = v + 1
      h = h + 1
   
setup()

[LAB6] Classroom #2D_Array

def setup():
   first_floors = [26, 32, 18, 17]
   second_floors = [16, 15, 24, 31]
   third_floors = [19, 26, 21, 30]
   buildings = [first_floors,second_floors,third_floors]
   #total_chairs(buildings)
   #find_max_floor(buildings)
   find_max_room(buildings)

def total_chairs(buildings):
   i = 0
   total = 0
   while(i < len(buildings)):
         choose = 0
         while(choose < len(buildings[i])):
            total = total + buildings[i][choose]
            choose = choose + 1
         i = i + 1
   print(total)
 
def find_max_floor(buildings):
   i = 0
   max_floor = 0
   total = 0
   ref = 0
   while(i < len(buildings)):
      choose = 0
      while(choose < len(buildings[i])):
            total = total + buildings[i][choose]
            choose = choose + 1
      if(total > ref):
         ref = total
         max_floor = i
      i = i + 1
   print(max_floor)
 
def find_max_room(buildings):
   i = 0
   ref = buildings[0][0]
   while(i < len(buildings)):
      choose = 0
      while(choose < len(buildings[i])):
         if(buildings[i][choose] > ref):
            ref = buildings[i][choose]
         choose = choose + 1
      i = i + 1
   i = 0
   while(i < len(buildings)):
      choose = 0
      while(choose < len(buildings[i])):
         if(ref == buildings[i][choose]):
            print("[",i,"][",choose,"]")
         choose = choose + 1
      i = i + 1
 
setup()

[LAB6] WEIGHT data

def setup():
   names = [ "art", "bird", "cat"]
   student_id = [ 22, 24,17]
   ages = [ 30, 21, 17]
   weights = [ 72, 53, 49]
   heights = [ 168, 169, 181]
   #min_weight(names,weights)
   count_weight50down(names,weights)
 
def min_weight(names,weights):
   i = 0
   min_w = weights[i]
   min_n = 0
   while(i < len(weights)):
      if(min_w > weights[i]):
         min_w = weights[i]
         min_n = names[i]
      i = i + 1
   print(min_n)
   print(min_w)

def count_weight50down(names,weights):
   i = 0
   count = 0
   while(i < len(weights)):
      if(weights[i] < 50):
         count = count + 1
         print(names[i])
         print("Weights =",weights[i])
      i = i + 1
   #print("count_weight50down ="count)

setup()

[LAB6] AGE (+insertion sort)

def setup():
   names = [ "art", "bird", "cat"]
   student_id = [ 22, 24,17]
   ages = [ 30, 21, 17]
   weights = [ 72, 53, 51]
   heights = [ 168, 169, 181]
   #average_age(ages)
   #age30down(names,ages)
   sort(names,ages)

def average_age(ages):
   i = 0
   total = 0
   a = 0
   while(i < len(ages)):
      total = total + ages[i]
      i = i + 1
   a = total / len(ages)
   print("average =","%.2f"%a)

def age30down(names,ages):
   i = 0
   while(i < len(names)):
      if(ages[i] < 30):
         print(names[i])
         print("age =",ages[i])
      i = i + 1
   
def sort(names,ages):
   i = 0
   j = 1
   charge = 0
   min_age = 0
   while(i < len(ages)):
      min_age = ages[i]
      while(j < len(ages)):
         if(min_age > ages[j]):
            charge = min_age
            min_age = ages[j]
            ages[j] = charge
         j = j + 1
      print(names[i])
      print(ages[i])
      print("")
      i = i + 1
 
setup()

[LAB6] BMI data

def setup():
   names = [ "art", "bird", "cat"]
   student_id = [ 22, 24,17]
   ages = [ 17, 18, 19]
   weights = [ 72, 53, 51]
   heights = [ 168, 169, 181]
   BMI(names, weights, heights)
 
def BMI(names, weights, heights):
   i = 0
   count = 0
   while(i < len(names)):
      BMI = weights[i]/((heights[i]/100) * (heights[i]/100))
      #print(names[i],"BMI =","%.2f"%BMI)
      if(BMI > 25):
         count = count + 1
         print("count_bmi25up =",count)
         print(names[i])
         print("weight", weights[i])
         print("height", heights[i])
         print("BMI =", "%.2f"%BMI)
      i = i + 1
     
setup()

[LAB6] Display student records (data)

def setup():
   names = [ "art", "bird", "cat"]
   student_id = [ 22, 24,17]
   ages = [ 17, 18, 19]
   weights = [ 48, 53, 51]
   heights = [ 174, 168, 181]
   show_student(names,student_id,ages,weights,heights)
 
def show_student(names,student_id,ages,weights,heights):
   i = 0
   while(i < len(names)):
      print("Name :",names[i])
      print("Id :",student_id[i])
      print("Age :",ages[i])
      print("Weight :",weights[i])
      print("Height :",heights[i])
      print()
      i = i + 1
 
setup()

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

[LAB5] my_endswith()

def my_endswith():
   my_endswith = 'Thailand'
   check = False
   word = 'and'
   first_index = len(word)-1
   second_index = len(my_endswith)-1
   count = 0
   k = 0
   if(len(my_endswith) >= len(word)):
      while(k < len(word)):
         if(word[first_index] == my_endswith[second_index]):
            count = count +1
         first_index = first_index - 1
         second_index = second_index - 1
         k = k + 1
         if(count != 0 and count%len(word) == 0):
            check = True
   return check

print(my_endswith())

[LAB5] my_startswith()

def my_statswith():
   my_startswith = 'Thailand'
   check = True
   word = 'Sun'
   count = 0
   if(len(my_startswith) > len(word)):
      while(count < len(word)):
         if(my_startswith[count] == word[count]):
            check = True
         else:
            check = False
         count = count + 1
   return check

print(my_statswith())

[LAB5] my_replace()

def my_place1():
   my_place1 = "Thai"
   return my_place1

def my_place2():
   my_place2 = "land"
   return my_place2

def my_place():
   return my_place1() + my_place2()

def my_replace():
   my_replace = "thai"
   return my_place1() + my_replace

print(my_place())
print(my_replace())

[LAB5] my_find()

def my_find():
   my_find = "Thailand"
   count = 0
   index = count
   while(count < len(my_find)):
      if(my_find[count] == "i"):
         index = count
      count = count + 1
   return index

print(my_find())

[LAB5] my_count()

def my_count():
   my_count = "Thailand"
   count = 0
   unit = count
   while(count < len(my_count)):
      if(my_count[count] == "a"):
         unit = unit + 1
      count = count + 1
   return unit

print(my_count())

[LAB5] Convert Base 10 --> Base 2

def convertBase2(number,base):
   convert = "0123456789"
   if number < base:
      return convert[number]
   else:
      return convertBase2(number//base,base) + convert[number%base]

print(convertBase2(10,2))

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

[LAB5] my_strip()

def my_strip():
   my_strip = 'Thailand   '
   current = '        '
   my_newstrip = ''
   count = 0
   while(count < len(my_strip)):
      if(count < len(current)):
         my_newstrip = my_newstrip + my_strip[count]
      count = count + 1
   return my_newstrip
 
print(my_strip())

[LAB5-Draft] INC/DEC VALUE (Fixed value)

def update_value(number):
    count = 0
    update = 5
    while(count < len(number)):
        number[count] = number[count] + update
        count = count + 1
    return number
         
def setup():
    number = [2,10,5,6,1]
    print(update_value(number))

setup()