วันอาทิตย์ที่ 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 ขึ...