วันอังคารที่ 20 ตุลาคม พ.ศ. 2558

Lab06 : Building


 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
def setup():
    floor1=[10,10,10,15,30]
    floor2=[20,40,10,75,15]
    floor3=[35,20,75,25,30]
    building=[floor1,floor2,floor3]
    display_2D(building)
    print ("Total chairs:",sum_2D(building))
    print("index of floor with maximum chair in building: ",end='')
    index_max(building)
    print("index of room with max chair in building:",end=' ')
    index_max_2D(building)
# ========================= 2D =========================
def index_max_2D(b):
    max=find_max(b[0],"value")
    i=1
    while i<len(b):
        if max<find_max(b[i],"value"):
            max=find_max(b[i],"value") # max of 2D
        i+=1
    i=0
    while i<len(b):
        if find_max(b[i],"value")==max:
            print("[",i,find_max(b[i],"index"),"]",end='')
        i+=1
    print()
def index_max(b):
    i=1
    max=0
    while i<len(b):
        if sum_1D(b[max])<sum_1D(b[i]):
            max=i
        i+=1
    print(max,"[ total:",sum_1D(b[max]),"]")
def display_2D(aa):
    i=0
    while i<len(aa):
        print("floor ",i,end='-> ')
        display_1D(aa[i])
        print()
        i+=1
def sum_2D(b):
    i=0
    sum=0
    while i<len(b):
        sum+=sum_1D(b[i])
        i+=1
    return sum
# ========================= 1D =========================
def sum_1D(a):
    i=0
    sum=0
    while i<len(a):
        sum+=a[i]
        i+=1
    return sum
def display_1D(a):
    i=0
    while i<len(a):
        print(a[i],end=' ')
        i+=1
def find_max(a,mode):
    max=a[0]
    max_index=0
    i=0
    while i<len(a):
        if a[i]>max:
            max=a[i]
            max_index=i
        i+=1
    if mode=="value":
        return max
    elif mode=="index":
        return max_index

setup()
http://pastebin.com/YLNf2sng

ไม่มีความคิดเห็น:

แสดงความคิดเห็น

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

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