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

report rasbery

1.เครื่องช้ามาก
2.เนตก็หลุดบ่อย
3.ทดลองสร้าง Animation จาก scratch

วันพฤหัสบดีที่ 26 พฤศจิกายน พ.ศ. 2558

Create class Banner for printing a banner

class Abc:
    def __init__(self,line1,line2,line3,line4,line5):
        self.line1 = line1
        self.line2 = line2
        self.line3 = line3
        self.line4 = line4
        self.line5 = line5
       
    def display_line1(self):
        print(self.line1,end = "")
    def display_line2(self):
        print(self.line2,end = "")
    def display_line3(self):
        print(self.line3,end = "")
    def display_line4(self):
        print(self.line4,end = "")
    def display_line5(self):
        print(self.line5,end = "")
                     
    def get_line1(self):
        return self.line1
    def get_line2(self):
        return self.line2
    def get_line3(self):
        return self.line3
    def get_line4(self):
        return self.line4
    def get_line5(self):
        return self.line5
                     
    def print_star_L1(self):
        hash_to_star(self.line1)
    def print_star_L2(self):
        hash_to_star(self.line2)
    def print_star_L3(self):
        hash_to_star(self.line3)
    def print_star_L4(self):
        hash_to_star(self.line4)
    def print_star_L5(self):
        hash_to_star(self.line5)
     
def hash_to_star(a):
    i = 0
    while(i < len(a)):
        if(a[i]  == "#"):
            print("*",end = "")
        else:
            print(" ",end = "")
        i += 1

def draw(group,word):  
    i = 0
    while(i < 5):
        k = 0
        while(k < len(word)):
            if(word[k] == "A"):
                print_fn(group,i,0)
            elif(word[k] == "B"):
                print_fn(group,i,1)
            elif(word[k] == "C"):
                print_fn(group,i,2)
            elif(word[k] == "D"):
                print_fn(group,i,3)
            k += 1
        print()
        i += 1

def print_fn(group,i,index):
    if(i == 0):
        group[index].print_star_L1()
    elif(i == 1):
        group[index].print_star_L2()
    elif(i == 2):
        group[index].print_star_L3()
    elif(i == 3):
        group[index].print_star_L4()
    elif(i == 4):
        group[index].print_star_L5()

def setup():
    A = Abc(" ###### ",
            " #    # ",
            " ###### ",
            " #    # ",
            " #    # " )
    B = Abc(" #####  ",
            " #    # ",
            " #####  ",
            " #    # ",
            " #####  " )
    C = Abc("  ####  ",
            " #      ",
            " #      ",
            " #      ",
            "  ####  " )
    D = Abc(" #####  ",
            " #     #",
            " #     #",
            " #     #",
            " #####  " )
    group = [A,B,C,D]
    word = input("")
    draw(group,word)
                               


setup()

วันพุธที่ 25 พฤศจิกายน พ.ศ. 2558

rasbery

class Student:
    def  __init__(self,name,ID,score):
        self.name=name
        self.ID=ID
        self.score=score

    def get_name(self):
        return self.name
    def get_ID(self):
        return self.ID
    def get_score(self):
        return self.score
    def set_score(self,s):
        return self.s

    def Display(self):
        print("Name",self.name)
        print("ID",self.ID)
        print("Score",self.score)

def setup():
    std=[Student("AA",11111,55),Student("BB",22222,80),Student("CC",33333,100),
         Student("DD",44444,70),Student("DD",55555,60)]
    x=std[0]
   
    grade(std)
    print("=-----------------------------------------------=")
    print("Grade =",findgrade(x))
    x.Display()
    countgrade(std)
    print("++++++++++++++++++++++++++++++++++++++++++++++++")
    showallgrade(std)


def findgrade(y):
    grade=""
     
   
    if(y.get_score()<50):
        grade="F"
           
    if(y.get_score()>=50 and y.get_score()<60):
        grade="D"
           
    if(y.get_score()>=60 and y.get_score()<70):
        grade="C"
           
    if(y.get_score()>=70 and y.get_score()<80):
        grade="B"
           
    if(y.get_score()>=80 and y.get_score()<=100):
        grade="A"
   
    return grade

def showallgrade(y):
    i=0
    grade=""
    while(i<len(y)):
        grade=""
        if(y[i].get_score() < 50 and y[i].get_score() >= 0):
            grade="F"
           
        elif(y[i].get_score()>=50 and y[i].get_score()<60):
            grade="D"
           
        elif(y[i].get_score()>=60 and y[i].get_score()<70):
            grade="C"
           
        elif(y[i].get_score()>=70 and y[i].get_score()<80):
            grade="B"
           
        elif(y[i].get_score()>=80 and y[i].get_score()<=100):
            grade="A"
           
        y[i].Display()
        print("Grade=",grade)
        print()
        i=i+1
       
       
def countgrade(std):
    i=0
    count=0
    while(i<len(std)):
        if(findgrade(std[i])=="A"):
            count=count+1
        i=i+1
    print("count of A=",count)
def grade(y):
    i=0
    while(i<len(y)):
        y[i].Display()
        print()
        i=i+1
    print()
       
setup()

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

Display student records with weight < 50

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160),
          Student('DDD',55233,30,55,170),
          Student('EEE',55555,10,30,120)]
   count_weight(std)
 
 
def count_weight(std):
   i=0
   count=0
   while(i<len(std)):
      if(std[i].get_weight()<50):
         std[i].display()
      i=i+1
 

     
                 
setup()

Find/count number of students with weight < 50

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160),
          Student('DDD',55233,30,55,170),
          Student('EEE',55555,10,30,120)]
   count_weight(std)
 
 
def count_weight(std):
   i=0
   count=0
   while(i<len(std)):
      if(std[i].get_weight()<50):
         count=count+1
      i=i+1
   print(count)

     
                 
setup()

Find minimum weight of students

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160),
          Student('DDD',55233,30,55,170),
          Student('EEE',55555,10,30,120)]
   mini_weight(std)
   displayweight(std)
 
 
def mini_weight(std):
   i=0
   while(i<len(std)):
      if (i != len(std)-1 and std[i].get_weight() > std[i+1].get_weight()):
         j = i
         while(j>=0):
            if(std[j].get_weight() > std[j+1].get_weight()):
               copy=std[j]
               std[j]=std[j+1]
               std[j+1]=copy
            j=j-1
             
      i=i+1
     
def displayweight(std):
   std[0].display()
     
                 
setup()

Display student records, sorted by age, use insertion sort

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160),
          Student('DDD',55233,30,55,170),
          Student('EEE',55555,10,30,120)]
   sort_age(std)
   displaysort(std)
 
def sort_age(std):
   i=0
   while(i<len(std)):
      if (i != len(std)-1 and std[i].get_age() > std[i+1].get_age()):
         j = i
         while(j>=0):
            if(std[j].get_age() > std[j+1].get_age()):
               copy=std[j]
               std[j]=std[j+1]
               std[j+1]=copy
            j=j-1
             
      i=i+1
     
def displaysort(std):
   i=0
   while(i<len(std)):
      std[i].display()
      i=i+1
                 
setup()

Find/count number of students with age < 30

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160)]
   count_age(std)
 
def count_age(std):
   i=0
   count = 0
   while(i<len(std)):
      if(std[i].get_age()<30):
         count=count+1
     
      i=i+1
     
 
   print(count)
 
 
setup()

Find average age of students

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160)]
   average_age(std)
 
def average_age(std):
   i=0
   sum=0
   while(i<len(std)):
      sum=sum+std[i].get_age()
      i=i+1
     
   avr = sum/len(std)
   print(avr)
 
 
setup()

Display student records with BMI > 25

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
   def display(self):
      print(self.name)
     
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160)]
   BMI(std)

def BMI(std):
   i=0
   while(i<len(std)):
      BMI=std[i].get_weight() / (std[i].get_height()/100)*(std[i].get_height()/100)
     
      if(BMI>25):
         print(std[i].display(),'BMI=',BMI)
         print()
      i=i+1
         

setup()

Find/count number of students with BMI > 25

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 

def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160)]
   count_BMI(std)

def count_BMI(std):    
   i=0
   count=0
   while(i<len(std)):
      BMI=std[i].get_weight() / (std[i].get_height()/100)*(std[i].get_height()/100)
      if(BMI>25):
         count=count+1
      i=i+1
   print(count)

setup()

Display each student record

class 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('Name',self.name)
      print('ID',self.ID)
      print('Ages',self.age)
      print("weight",self.weight)
      print("height",self.height)
      print()
     
def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160)]
   displaystudent(std)
def displaystudent(std):
   i=0
   while(i<len(std)):
      std[i].display()
      i += 1
setup()

Find student BMI

class 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 get_name(self):
      return self.name
   def get_ID(self):
      return self.ID
   def get_age(self):
      return self.age
   def get_weight(self):
      return self.weight
   def get_height(self):
      return self.height
 
 
   def display(self):
      print(self.name,"",end="")
      print(BMI(self))
      print()
     
 

def setup():
   std = [Student('AAA',54321,20,45,145),
          Student('BBB',52345,18,50,155),
          Student('CCC',55123,25,45,160)]
   displayBMI(std)
 

 
def BMI(self):
   BMI = self.get_weight() / (self.get_height()/100)*(self.get_height()/100)
   return BMI

def displayBMI(std):
   i=0
   while(i<len(std)):
      std[i].display()
      i += 1
       
 
setup()

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

-Write a function that takes a string as an argument and prints out the string in large letters

def setup():
    word = input()
    draw(word)

def draw(w):
    A1 = "     #     "
    A2 = "    # #    "
    A3 = "   #####   "
    A4 = "  #     #  "
    A5 = " #       # "
    A = [A1,A2,A3,A4,A5]
    E1 = " ###### "
    E2 = " #      "
    E3 = " ###### "
    E4 = " #      "
    E5 = " ###### "
    E = [E1,E2,E3,E4,E5]
    C1 = " ###### "
    C2 = " #      "
    C3 = " #      "
    C4 = " #      "
    C5 = " ###### "
    C = [C1,C2,C3,C4,C5]
     
    i = 0
    while(i < 5):
        j = 0
        while(j < len(w)):
            if(w[j] == "A"):
                print(A[i],end = "")
            elif(w[j] == "E"):
                print(E[i],end = "")
            elif(w[j] == "C"):
                print(C[i],end = "")
           
            j += 1
        print()
        i += 1
                                 
setup()