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

Lab07 : String Text

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
class banner:
    def __init__ (self,text,style):
        self.text=text
        self.style=style
    def display(self):
        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]
        s1="####  "
        s2="#     "
        s3="####  "
        s4="   #  "
        s5="####  "
        S=[ s1, s2, s3, s4, s5]
        j=0
        while j<5:
            i=0
            while i<len(self.text):
                if self.text[i]=="A":
                    A[j]=replace_one(A[j],"#",self.style)
                    print(A[j],end='')
                if self.text[i]=="E":
                    E[j]=replace_one(E[j],"#",self.style)
                    print(E[j],end='')
                if self.text[i]=="C":
                    C[j]=replace_one(C[j],"#",self.style)
                    print(C[j],end='')
                if self.text[i]=="S":
                    S[j]=replace_one(S[j],"#",self.style)
                    print(S[j],end='')
                i+=1
            print()
            j+=1
    def setStyle(self,style):
        self.style=style
def setup():
    text=input("input text:")
    B=banner(text,"+")
    B.display()
    B.setStyle("*")
    B.display()   
    B.setStyle("#")
    B.display()   
def replace_one(t,s,r):
    i=0
    text=""
    while i<len(t):
        if t[i]!=s:
            text+=t[i]
        else:
            text+=r
        i+=1
    return text
setup()

https://repl.it/BUU7

Lab07 : Insertion sort

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class student:
    def __init__(self,id_num,name,age,weight,height):
        self.id_num=id_num
        self.name=name
        self.age=age
        self.weight=weight
        self.height=height
    def display(self):
        print("id:",self.id_num)
        print("name:",self.name)
        print("age:",self.age)
        print("weight:",self.weight)
        print("height:",self.height)
    def getWeight(self):
        return self.weight
    def getHeight(self):
        return self.height
    def getAge(self):
        return self.age
    def getID(self):
        return self.id_num
    def getName(self):
        return self.name
    def setWeight(self,w):
        self.weight=w
    def setHeight(self,h):
        self.height=h
    def setAge(self,age):
        self.age=age
    def setID(self,id):
        self.id_num=id
    def setName(self,name):
        self.name=name


def setup():
    a=student(1,"John",18,100,160)
    b=student(2,"Jo",20,50,180)
    c=student(3,"Jan",17,42,150)
    d=student(4,"ISH",19,55,170)
    stdnt=[a,b,c,d]
    insertion_sort_class(stdnt) #sort by age
    display_class(stdnt)

    
def display_class(stdnt):
    i=0
    while i<len(stdnt): #display
        stdnt[i].display()
        i+=1
def insertion_sort_class(stdnt): 
    i=1
    j=0
    while i<len(stdnt):
        j=i
        while j>0 and stdnt[j].getAge()<stdnt[j-1].getAge():#Age
            swap(j,j-1,stdnt)
            j-=1
        i+=1
def swap(i,k,stdnt): 
    temp=stdnt[i].getAge() #1
    stdnt[i].setAge(stdnt[k].getAge())
    stdnt[k].setAge(temp) 
    temp=stdnt[i].getWeight() #2
    stdnt[i].setWeight(stdnt[k].getWeight())
    stdnt[k].setWeight(temp) 
    temp=stdnt[i].getHeight() #3
    stdnt[i].setHeight(stdnt[k].getHeight())
    stdnt[k].setHeight(temp) 
    temp=stdnt[i].getID() #4
    stdnt[i].setID(stdnt[k].getID())
    stdnt[k].setID(temp) 
    temp=stdnt[i].getName() #5
    stdnt[i].setName(stdnt[k].getName())
    stdnt[k].setName(temp) 
setup()

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

Lab07 : Student Class

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class student:
    def __init__(self,id_num,name,age,weight,height):
        self.id_num=id_num
        self.name=name
        self.age=age
        self.weight=weight
        self.height=height
    def display(self):
        print("id:",self.id_num)
        print("name:",self.name)
        print("age:",self.age)
        print("weight:",self.weight)
        print("height:",self.height)
    def getWeight(self):
        return self.weight
    def getHeight(self):
        return self.height
    def getAge(self):
        return self.age
        
def setup():
    stdnt=[student(1,"John",18,100,160),
        student(2,"Jo",20,50,180),
        student(3,"Jan",17,42,150),
        student(4,"ISH",19,55,170)]
    display_class(stdnt)
    BMI(stdnt)
    age_class(stdnt)
    weight_class(stdnt)

def display_class(stdnt):
    i=0
    while i<len(stdnt): #display
        stdnt[i].display()
        i+=1
def BMI(student):
    bmi=[]
    i=0
    while i<len(student):
        m=student[i].getHeight()/100
        bmi.append(student[i].getWeight()/(m*m))
        i+=1
    print("********* Display BMI>25 *********")
    i=0
    count=0
    while i<len(bmi): #bmi>25
        if bmi[i]>25:
            count+=1
            student[i].display()
        i+=1
    print("Count BMI>25 :",count)
    print("************************************")
def age_class(stdnt):
    i=0
    sum=0
    while i<len(stdnt):
        sum+=stdnt[i].getAge()
        i+=1
    avg=sum/len(stdnt)
    print("Average age:",avg)
    i=0
    count_age=0
    while i<len(stdnt):
        if stdnt[i].getAge()<30:
            count_age+=1
        i+=1
    print("Age < 30 :",count_age)
def weight_class(stdnt):
    print("Min weight : ",min_class(stdnt))
    print("********* Display Weight<50 *********")
    i=0
    count_weight=0
    while i<len(stdnt): 
        if stdnt[i].getWeight()<50:
            count_weight+=1
            stdnt[i].display()
        i+=1
    print("Weight < 50 :",count_weight)
    print("************************************")
def min_class(a):
    min=a[0].getWeight()
    i=0
    while i<len(a):
        if a[i].getWeight()<min:
            min=a[i].getWeight()
        i+=1
    return min

setup()

commit เพิ่มเติม : เพื่ม userstory, bookmark

>>  add userstory ทำการเพิ่ม userstory ใน functional tests >>  add bookmark for user เพิ่มระบบ Bookmark โดยการสร้าง model ขึ...