class Alphabet:
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_alphabet_L1(self):
print(self.line1,end = "")
def display_alphabet_L2(self):
print(self.line2,end = "")
def display_alphabet_L3(self):
print(self.line3,end = "")
def display_alphabet_L4(self):
print(self.line4,end = "")
def display_alphabet_L5(self):
print(self.line5,end = "")
def get_alphabet_L1(self):
return self.line1
def get_alphabet_L2(self):
return self.line2
def get_alphabet_L3(self):
return self.line3
def get_alphabet_L4(self):
return self.line4
def get_alphabet_L5(self):
return self.line5
def print_star_L1(self):
hastag_to_star(self.line1)
def print_star_L2(self):
hastag_to_star(self.line2)
def print_star_L3(self):
hastag_to_star(self.line3)
def print_star_L4(self):
hastag_to_star(self.line4)
def print_star_L5(self):
hastag_to_star(self.line5)
def hastag_to_star(temp):
i = 0
while(i < len(temp)):
if(temp[i] == "#"):
print("*",end = "")
else:
print(" ",end = "")
i += 1
def draw_alphabet(alphabet_group,word):
ip = 0
while(ip < 5):
iw = 0
while(iw < len(word)):
if(word[iw] == "B"):
print_func(alphabet_group,ip,0)
elif(word[iw] == "L"):
print_func(alphabet_group,ip,1)
elif(word[iw] == "U"):
print_func(alphabet_group,ip,2)
elif(word[iw] == "E"):
print_func(alphabet_group,ip,3)
iw += 1
print()
ip += 1
def print_func(alphabet_group,ip,alphabet_index):
if(ip == 0):
alphabet_group[alphabet_index].print_star_L1()
elif(ip == 1):
alphabet_group[alphabet_index].print_star_L2()
elif(ip == 2):
alphabet_group[alphabet_index].print_star_L3()
elif(ip == 3):
alphabet_group[alphabet_index].print_star_L4()
elif(ip == 4):
alphabet_group[alphabet_index].print_star_L5()
def setup():
B = Alphabet(" ##### ",
" # # ",
" ##### ",
" # # ",
" ##### " )
L = Alphabet(" # ",
" # ",
" # ",
" # ",
" ###### " )
U = Alphabet(" # # ",
" # # ",
" # # ",
" # # ",
" #### " )
E = Alphabet(" ###### ",
" # ",
"###### ",
" # ",
" ###### " )
alphabet_group = [B,L,U,E]
word = input("")
draw_alphabet(alphabet_group,word)
setup()
วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2558
Display student records, sorted by age, use insertion sort.
class Students:
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("Age:",self.age)
print("Weight:",self.weight)
print("Height:",self.height)
print()
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 set_name(self,name):
self.name = name
def set_ID(self,ID):
self.ID = ID
def set_age(self,age):
self.age = age
def set_weight(self,weight):
self.weight = weight
def set_height(self,height):
self.height = height
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 48, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
sort(nukrean)
a.display()
b.display()
c.display()
d.display()
def sort(nukrean):
i = 1
while(i < len(nukrean)):
value_a = nukrean[i].get_age()
value_n = nukrean[i].get_name()
value_I = nukrean[i].get_ID()
value_w = nukrean[i].get_weight()
value_h = nukrean[i].get_height()
j = i
while(j>0 and nukrean[j-1].get_age() > value_a):
nukrean[j].set_age(nukrean[j-1].get_age())
nukrean[j].set_name(nukrean[j-1].get_name())
nukrean[j].set_ID(nukrean[j-1].get_ID())
nukrean[j].set_weight(nukrean[j-1].get_weight())
nukrean[j].set_height(nukrean[j-1].get_height())
j = j - 1
nukrean[j].set_age(value_a)
nukrean[j].set_name(value_n)
nukrean[j].set_ID(value_I)
nukrean[j].set_weight(value_w)
nukrean[j].set_height(value_h)
i += 1
setup()
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("Age:",self.age)
print("Weight:",self.weight)
print("Height:",self.height)
print()
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 set_name(self,name):
self.name = name
def set_ID(self,ID):
self.ID = ID
def set_age(self,age):
self.age = age
def set_weight(self,weight):
self.weight = weight
def set_height(self,height):
self.height = height
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 48, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
sort(nukrean)
a.display()
b.display()
c.display()
d.display()
def sort(nukrean):
i = 1
while(i < len(nukrean)):
value_a = nukrean[i].get_age()
value_n = nukrean[i].get_name()
value_I = nukrean[i].get_ID()
value_w = nukrean[i].get_weight()
value_h = nukrean[i].get_height()
j = i
while(j>0 and nukrean[j-1].get_age() > value_a):
nukrean[j].set_age(nukrean[j-1].get_age())
nukrean[j].set_name(nukrean[j-1].get_name())
nukrean[j].set_ID(nukrean[j-1].get_ID())
nukrean[j].set_weight(nukrean[j-1].get_weight())
nukrean[j].set_height(nukrean[j-1].get_height())
j = j - 1
nukrean[j].set_age(value_a)
nukrean[j].set_name(value_n)
nukrean[j].set_ID(value_I)
nukrean[j].set_weight(value_w)
nukrean[j].set_height(value_h)
i += 1
setup()
Find/count number of students with weight < 50.
class Students:
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_weight(self):
return self.weight
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 48, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
find(nukrean)
def find(nukrean):
i = 0
count = 0
while(i < len(nukrean)):
if(nukrean[i].get_weight() < 50):
print(nukrean[i].get_name(),"weight = ",nukrean[i].get_weight())
count = count + 1
i = i + 1
print("Have",count,"Students")
setup()
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_weight(self):
return self.weight
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 48, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
find(nukrean)
def find(nukrean):
i = 0
count = 0
while(i < len(nukrean)):
if(nukrean[i].get_weight() < 50):
print(nukrean[i].get_name(),"weight = ",nukrean[i].get_weight())
count = count + 1
i = i + 1
print("Have",count,"Students")
setup()
Find minimum weight of students.
class Students:
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_weight(self):
return self.weight
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
minimum(nukrean)
def minimum(nukrean):
i = 0
min = nukrean[i].get_weight()
while(i < len(nukrean)):
if(nukrean[i].get_weight() < min):
min = nukrean[i].get_weight()
i = i + 1
print("Minimum is",min)
setup()
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_weight(self):
return self.weight
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
minimum(nukrean)
def minimum(nukrean):
i = 0
min = nukrean[i].get_weight()
while(i < len(nukrean)):
if(nukrean[i].get_weight() < min):
min = nukrean[i].get_weight()
i = i + 1
print("Minimum is",min)
setup()
Find/count number of students with age < 30.
class Students:
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_age(self):
return self.age
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
count(nukrean)
def count(nukrean):
i = 0
count = 0
while(i < len(nukrean)):
if(nukrean[i].get_age() < 30):
count = count + 1
i = i + 1
print("Have",count,"Students")
setup()
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_age(self):
return self.age
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
count(nukrean)
def count(nukrean):
i = 0
count = 0
while(i < len(nukrean)):
if(nukrean[i].get_age() < 30):
count = count + 1
i = i + 1
print("Have",count,"Students")
setup()
Find average age of students.
class Students:
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_age(self):
return self.age
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
average(nukrean)
def average(nukrean):
i = 0
count = 0
sum = 0
a = 0
while(i < len(nukrean)):
sum = sum + nukrean[i].get_age()
count = count + 1
a = sum/count
i = i + 1
print("Average = ",a)
setup()
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_age(self):
return self.age
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
average(nukrean)
def average(nukrean):
i = 0
count = 0
sum = 0
a = 0
while(i < len(nukrean)):
sum = sum + nukrean[i].get_age()
count = count + 1
a = sum/count
i = i + 1
print("Average = ",a)
setup()
Find/count&display number of students with BMI > 25.
class Students:
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_weight(self):
return self.weight
def get_height(self):
return self.height
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
BMI(nukrean)
def BMI(nukrean):
i = 0
count = 0
while(i < len(nukrean)):
BMI = nukrean[i].get_weight()/pow((nukrean[i].get_height()/100),2)
if(BMI > 25):
print(nukrean[i].get_name()," = ","%.3f"%BMI)
count = count + 1
i = i + 1
print("Have",count,"Students")
setup()
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_weight(self):
return self.weight
def get_height(self):
return self.height
def setup():
a = Students("Gun", 32075, 26, 90, 174)
b = Students("Rit", 32078, 25, 80, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 70, 168)
nukrean = [a, b, c, d]
BMI(nukrean)
def BMI(nukrean):
i = 0
count = 0
while(i < len(nukrean)):
BMI = nukrean[i].get_weight()/pow((nukrean[i].get_height()/100),2)
if(BMI > 25):
print(nukrean[i].get_name()," = ","%.3f"%BMI)
count = count + 1
i = i + 1
print("Have",count,"Students")
setup()
Find student BMI.
class Students:
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_weight(self):
return self.weight
def get_height(self):
return self.height
def setup():
a = Students("Gun", 32075, 26, 70, 174)
b = Students("Rit", 32078, 25, 60, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 65, 168)
nukrean = [a, b, c, d]
BMI(nukrean)
def BMI(nukrean):
i = 0
while(i < len(nukrean)):
BMI = nukrean[i].get_weight()/pow((nukrean[i].get_height()/100),2)
print(nukrean[i].get_name()," = ","%.3f"%BMI)
i = i + 1
setup()
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_weight(self):
return self.weight
def get_height(self):
return self.height
def setup():
a = Students("Gun", 32075, 26, 70, 174)
b = Students("Rit", 32078, 25, 60, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 65, 168)
nukrean = [a, b, c, d]
BMI(nukrean)
def BMI(nukrean):
i = 0
while(i < len(nukrean)):
BMI = nukrean[i].get_weight()/pow((nukrean[i].get_height()/100),2)
print(nukrean[i].get_name()," = ","%.3f"%BMI)
i = i + 1
setup()
วันอาทิตย์ที่ 25 ตุลาคม พ.ศ. 2558
Display each student record.
class Students:
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("Age:",self.age)
print("Weight:",self.weight)
print("Height:",self.height)
def setup():
a = Students("Gun", 32075, 26, 70, 174)
b = Students("Rit", 32078, 25, 60, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 65, 168)
a.display()
print()
b.display()
print()
c.display()
print()
d.display()
setup()
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("Age:",self.age)
print("Weight:",self.weight)
print("Height:",self.height)
def setup():
a = Students("Gun", 32075, 26, 70, 174)
b = Students("Rit", 32078, 25, 60, 170)
c = Students("Frame", 32080, 19, 58.2, 173)
d = Students("Boat", 32057, 16, 65, 168)
a.display()
print()
b.display()
print()
c.display()
print()
d.display()
setup()
วันจันทร์ที่ 19 ตุลาคม พ.ศ. 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(word):
Bl1 = " ##### "
Bl2 = " # # "
Bl3 = " ##### "
Bl4 = " # # "
Bl5 = " ##### "
B = [Bl1,Bl2,Bl3,Bl4,Bl5]
Ll1 = " # "
Ll2 = " # "
Ll3 = " # "
Ll4 = " # "
Ll5 = " ###### "
L = [Ll1,Ll2,Ll3,Ll4,Ll5]
Ul1 = " # # "
Ul2 = " # # "
Ul3 = " # # "
Ul4 = " # # "
Ul5 = " #### "
U = [Ul1,Ul2,Ul3,Ul4,Ul5]
El1 = " ###### "
El2 = " # "
El3 = " ###### "
El4 = " # "
El5 = " ###### "
E = [El1,El2,El3,El4,El5]
ip = 0
while(ip < 5):
iw = 0
while(iw < len(word)):
if(word[iw] == "B"):
print(B[ip],end = "")
elif(word[iw] == "L"):
print(L[ip],end = "")
elif(word[iw] == "U"):
print(U[ip],end = "")
elif(word[iw] == "E"):
print(E[ip],end = "")
iw += 1
print()
ip += 1
setup()
word = input("")
draw(word)
def draw(word):
Bl1 = " ##### "
Bl2 = " # # "
Bl3 = " ##### "
Bl4 = " # # "
Bl5 = " ##### "
B = [Bl1,Bl2,Bl3,Bl4,Bl5]
Ll1 = " # "
Ll2 = " # "
Ll3 = " # "
Ll4 = " # "
Ll5 = " ###### "
L = [Ll1,Ll2,Ll3,Ll4,Ll5]
Ul1 = " # # "
Ul2 = " # # "
Ul3 = " # # "
Ul4 = " # # "
Ul5 = " #### "
U = [Ul1,Ul2,Ul3,Ul4,Ul5]
El1 = " ###### "
El2 = " # "
El3 = " ###### "
El4 = " # "
El5 = " ###### "
E = [El1,El2,El3,El4,El5]
ip = 0
while(ip < 5):
iw = 0
while(iw < len(word)):
if(word[iw] == "B"):
print(B[ip],end = "")
elif(word[iw] == "L"):
print(L[ip],end = "")
elif(word[iw] == "U"):
print(U[ip],end = "")
elif(word[iw] == "E"):
print(E[ip],end = "")
iw += 1
print()
ip += 1
setup()
Transpose a square matrix in place without creating a new matrix.
def setup():
rowone = [41, 22, 83]
rowtwo = [12, 62, 72]
rowthree = [38, 15, 98]
maxtrix= [rowone, rowtwo, rowthree]
dis(maxtrix)
tran(maxtrix)
print()
print("After")
print()
dis(maxtrix)
def dis(maxtrix):
i = 0
while(i < len(maxtrix)):
j = 0
print("|",end = "")
while(j < len(maxtrix[i])):
print(" ",maxtrix[i][j]," ",end = "")
j += 1
print("|")
i +=1
def tran(maxtrix):
i = 0
while(i < len(maxtrix)):
j = i
while(j < len(maxtrix[i])):
temp = maxtrix[i][j]
maxtrix[i][j] = maxtrix[j][i]
maxtrix[j][i] = temp
j = j + 1
i = i + 1
setup()
rowone = [41, 22, 83]
rowtwo = [12, 62, 72]
rowthree = [38, 15, 98]
maxtrix= [rowone, rowtwo, rowthree]
dis(maxtrix)
tran(maxtrix)
print()
print("After")
print()
dis(maxtrix)
def dis(maxtrix):
i = 0
while(i < len(maxtrix)):
j = 0
print("|",end = "")
while(j < len(maxtrix[i])):
print(" ",maxtrix[i][j]," ",end = "")
j += 1
print("|")
i +=1
def tran(maxtrix):
i = 0
while(i < len(maxtrix)):
j = i
while(j < len(maxtrix[i])):
temp = maxtrix[i][j]
maxtrix[i][j] = maxtrix[j][i]
maxtrix[j][i] = temp
j = j + 1
i = i + 1
setup()
Multiply two matrices.
def setup():
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
mul(maxtrixone,maxtrixtwo)
def mul(maxtrixone,maxtrixtwo):
i = 0
ii = 0
ki = 0
while(ii < len(maxtrixone)):
j = 0
ij = 0
kj = 0
print("|", end = "")
while(ij < len(maxtrixtwo[i])):
tempone = maxtrixone[i+ki][j]*maxtrixtwo[i][j+kj]
temptwo = maxtrixone[i+ki][j+1]*maxtrixtwo[i+1][j+kj]
tempthree = maxtrixone[i+ki][j+2]*maxtrixtwo[i+2][j+kj]
print(" ",tempone+temptwo+tempthree,end = " ")
kj += 1
ij += 1
print(" |")
ki += 1
ii += 1
setup()
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
mul(maxtrixone,maxtrixtwo)
def mul(maxtrixone,maxtrixtwo):
i = 0
ii = 0
ki = 0
while(ii < len(maxtrixone)):
j = 0
ij = 0
kj = 0
print("|", end = "")
while(ij < len(maxtrixtwo[i])):
tempone = maxtrixone[i+ki][j]*maxtrixtwo[i][j+kj]
temptwo = maxtrixone[i+ki][j+1]*maxtrixtwo[i+1][j+kj]
tempthree = maxtrixone[i+ki][j+2]*maxtrixtwo[i+2][j+kj]
print(" ",tempone+temptwo+tempthree,end = " ")
kj += 1
ij += 1
print(" |")
ki += 1
ii += 1
setup()
Subtract two matrices.
def setup():
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
subtwo(maxtrixone,maxtrixtwo)
def subtwo(maxtrixone,maxtrixtwo):
i = 0
while(i < len(maxtrixone)):
j = 0
print("|", end = "")
while(j < len(maxtrixone[i])):
print("",maxtrixone[i][j]-maxtrixtwo[i][j],"",end = "")
j = j + 1
print("|")
i = i + 1
setup()
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
subtwo(maxtrixone,maxtrixtwo)
def subtwo(maxtrixone,maxtrixtwo):
i = 0
while(i < len(maxtrixone)):
j = 0
print("|", end = "")
while(j < len(maxtrixone[i])):
print("",maxtrixone[i][j]-maxtrixtwo[i][j],"",end = "")
j = j + 1
print("|")
i = i + 1
setup()
Add two matrices.
def setup():
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
addtwo(maxtrixone,maxtrixtwo)
def addtwo(maxtrixone,maxtrixtwo):
i = 0
while(i < len(maxtrixone)):
j = 0
print("|", end = "")
while(j < len(maxtrixone[i])):
print("",maxtrixone[i][j]+maxtrixtwo[i][j],"",end = "")
j = j + 1
print("|")
i = i + 1
setup()
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
addtwo(maxtrixone,maxtrixtwo)
def addtwo(maxtrixone,maxtrixtwo):
i = 0
while(i < len(maxtrixone)):
j = 0
print("|", end = "")
while(j < len(maxtrixone[i])):
print("",maxtrixone[i][j]+maxtrixtwo[i][j],"",end = "")
j = j + 1
print("|")
i = i + 1
setup()
Display the matrix.
def setup():
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
display(maxtrixone)
print()
display(maxtrixtwo)
def display(maxtrixone):
i = 0
while(i < len(maxtrixone)):
j = 0
print("|", end = "")
while(j < len(maxtrixone[i])):
print("",maxtrixone[i][j],"",end = "")
j = j + 1
print("|")
i = i + 1
setup()
rowone = [1, 2, 3]
rowtwo = [2, 3, 4]
rowthree = [3, 4, 5]
maxtrixone = [rowone, rowtwo, rowthree]
rowfour = [4, 5, 6]
rowfive = [5, 6, 7]
rowsix = [6, 7, 8]
maxtrixtwo = [rowfour, rowfive, rowsix]
display(maxtrixone)
print()
display(maxtrixtwo)
def display(maxtrixone):
i = 0
while(i < len(maxtrixone)):
j = 0
print("|", end = "")
while(j < len(maxtrixone[i])):
print("",maxtrixone[i][j],"",end = "")
j = j + 1
print("|")
i = i + 1
setup()
Find indices of the room(s) with maximum number of chairs (in the building).
def setup():
one = [12, 24, 26, 28, 32]
two = [14, 27, 29, 31, 34]
three = [25, 26, 27, 36, 39]
four = [16, 18, 15, 14, 13]
b = [one, two, three, four]
find(b)
def find(b):
i_f = 0
value = b[0][0]
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
if(b[i_f][i_r] > value):
value = b[i_f][i_r]
i_r += 1
i_f += 1
i_f = 0
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
if( value == b[i_f][i_r]):
print("Indices is"," [",i_f,"][",i_r,"] ",end = "")
i_r += 1
i_f += 1
setup()
one = [12, 24, 26, 28, 32]
two = [14, 27, 29, 31, 34]
three = [25, 26, 27, 36, 39]
four = [16, 18, 15, 14, 13]
b = [one, two, three, four]
find(b)
def find(b):
i_f = 0
value = b[0][0]
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
if(b[i_f][i_r] > value):
value = b[i_f][i_r]
i_r += 1
i_f += 1
i_f = 0
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
if( value == b[i_f][i_r]):
print("Indices is"," [",i_f,"][",i_r,"] ",end = "")
i_r += 1
i_f += 1
setup()
Display student records, sorted by age, use insertion sort.
def setup():
name = ["Gun","Rit","Frame","Coffee","Ice","Boat"]
ID = [32075,32078,32080,32057,32087,33653]
age = [26,25,19,17,18,16]
weight = [80,75,58.2,60,65,55]
height = [174,170,173,165,168,163]
i = 0
sort(name,ID,age,weight,height)
while(i<len(weight)):
display(name,ID,age,weight,height,i)
i += 1
def display(n,I,a,w,h,i):
print(n[i])
print("ID =",I[i])
print("age =",a[i])
print("weight =",w[i])
print("height =",h[i])
print()
def sort(n,I,a,w,h):
i = 1
while(i<len(a)):
value_a = a[i]
value_n = n[i]
value_I = I[i]
value_w = w[i]
value_h = h[i]
j = i
while(j>0 and a[j-1] > value_a):
a[j] = a[j-1]
n[j] = n[j-1]
I[j] = I[j-1]
w[j] = w[j-1]
h[j] = h[j-1]
j = j - 1
a[j] = value_a
n[j] = value_n
I[j] = value_I
w[j] = value_w
h[j] = value_h
i += 1
setup()
name = ["Gun","Rit","Frame","Coffee","Ice","Boat"]
ID = [32075,32078,32080,32057,32087,33653]
age = [26,25,19,17,18,16]
weight = [80,75,58.2,60,65,55]
height = [174,170,173,165,168,163]
i = 0
sort(name,ID,age,weight,height)
while(i<len(weight)):
display(name,ID,age,weight,height,i)
i += 1
def display(n,I,a,w,h,i):
print(n[i])
print("ID =",I[i])
print("age =",a[i])
print("weight =",w[i])
print("height =",h[i])
print()
def sort(n,I,a,w,h):
i = 1
while(i<len(a)):
value_a = a[i]
value_n = n[i]
value_I = I[i]
value_w = w[i]
value_h = h[i]
j = i
while(j>0 and a[j-1] > value_a):
a[j] = a[j-1]
n[j] = n[j-1]
I[j] = I[j-1]
w[j] = w[j-1]
h[j] = h[j-1]
j = j - 1
a[j] = value_a
n[j] = value_n
I[j] = value_I
w[j] = value_w
h[j] = value_h
i += 1
setup()
Find index of the floor(s) with maximum number of chairs (in the building).
def setup():
one = [12, 24, 26, 28, 32]
two = [14, 27, 29, 31, 34]
three = [25, 26, 27, 36, 39]
four = [16, 18, 15, 14, 13]
b = [one, two, three, four]
find(b)
def find(b):
i_f = 0
total = 0
value = 0
imax = 0
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
total = total + b[i_f][i_r]
i_r = i_r +1
if(total > value):
value = total
imax = i_f
i_f = i_f + 1
print("Floor is",imax)
setup()
one = [12, 24, 26, 28, 32]
two = [14, 27, 29, 31, 34]
three = [25, 26, 27, 36, 39]
four = [16, 18, 15, 14, 13]
b = [one, two, three, four]
find(b)
def find(b):
i_f = 0
total = 0
value = 0
imax = 0
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
total = total + b[i_f][i_r]
i_r = i_r +1
if(total > value):
value = total
imax = i_f
i_f = i_f + 1
print("Floor is",imax)
setup()
Find total number of chairs (in the building).
def setup():
one = [12, 24, 26, 28, 32]
two = [14, 27, 29, 31, 34]
three = [25, 26, 27, 36, 39]
four = [16, 18, 15, 14, 13]
b = [one, two, three, four]
total(b)
def total(b):
i_f = 0
total = 0
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
total = total + b[i_f][i_r]
i_r = i_r +1
i_f = i_f + 1
print("Total is",total)
setup()
one = [12, 24, 26, 28, 32]
two = [14, 27, 29, 31, 34]
three = [25, 26, 27, 36, 39]
four = [16, 18, 15, 14, 13]
b = [one, two, three, four]
total(b)
def total(b):
i_f = 0
total = 0
while(i_f < len(b)):
i_r = 0
while(i_r < len(b[i_f])):
total = total + b[i_f][i_r]
i_r = i_r +1
i_f = i_f + 1
print("Total is",total)
setup()
Display student records with weight < 50.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 45, 50.2]
height = [1.74, 1.70, 1.73]
find(name, weight)
def find(n, w):
i = 0
while(i < len(w)):
if(w[i] < 50):
print(n[i], "weight =", w[i])
i = i + 1
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 45, 50.2]
height = [1.74, 1.70, 1.73]
find(name, weight)
def find(n, w):
i = 0
while(i < len(w)):
if(w[i] < 50):
print(n[i], "weight =", w[i])
i = i + 1
setup()
Find/count number of students with weight < 50.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 45, 50.2]
height = [1.74, 1.70, 1.73]
print(count(weight))
def count(w):
i = 0
count = 0
while(i < len(w)):
if(w[i] < 50):
count = count + 1
i = i + 1
return count
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 45, 50.2]
height = [1.74, 1.70, 1.73]
print(count(weight))
def count(w):
i = 0
count = 0
while(i < len(w)):
if(w[i] < 50):
count = count + 1
i = i + 1
return count
setup()
Find minimum weight of students.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
min(name, weight)
def min(n, w):
i = 0
namemin = 0
min = w[i]
while(i < len(w)):
if(min > w[i]):
min = w[i]
namemin = n[i]
i = i + 1
print(namemin,"is a minimum weight =",min)
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
min(name, weight)
def min(n, w):
i = 0
namemin = 0
min = w[i]
while(i < len(w)):
if(min > w[i]):
min = w[i]
namemin = n[i]
i = i + 1
print(namemin,"is a minimum weight =",min)
setup()
วันอาทิตย์ที่ 18 ตุลาคม พ.ศ. 2558
Find/count number of students with age < 30.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
print(count(age))
def count(age):
i = 0
count = 0
while(i < len(age)):
if(age[i] < 30):
count = count + 1
i = i + 1
return count
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [38, 83, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
print(count(age))
def count(age):
i = 0
count = 0
while(i < len(age)):
if(age[i] < 30):
count = count + 1
i = i + 1
return count
setup()
Find average age of students.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
print(average(age))
def average(age):
i = 0
sum = 0
n = 0
average = 0
while(i < len(age)):
sum = sum + age[i]
n = n + 1
average = sum/n
i = i + 1
return average
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
print(average(age))
def average(age):
i = 0
sum = 0
n = 0
average = 0
while(i < len(age)):
sum = sum + age[i]
n = n + 1
average = sum/n
i = i + 1
return average
setup()
Display student records with BMI > 25.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
find(name, weight, height)
def find(n, w, h):
i = 0
count = 0
while(i < len(n)):
BMI = w[i]/(h[i]*h[i])
if(BMI > 25):
print(n[i], "weight", w[i], "height", h[i], "BMI =", "%.2f"%BMI)
i = i + 1
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
find(name, weight, height)
def find(n, w, h):
i = 0
count = 0
while(i < len(n)):
BMI = w[i]/(h[i]*h[i])
if(BMI > 25):
print(n[i], "weight", w[i], "height", h[i], "BMI =", "%.2f"%BMI)
i = i + 1
setup()
Find/count number of students with BMI > 25.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
print(count(name, weight, height))
def count(n, w, h):
i = 0
count = 0
while(i < len(n)):
BMI = w[i]/(h[i]*h[i])
if(BMI > 25):
count = count + 1
i = i + 1
return count
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [80, 75, 58.2]
height = [1.74, 1.70, 1.73]
print(count(name, weight, height))
def count(n, w, h):
i = 0
count = 0
while(i < len(n)):
BMI = w[i]/(h[i]*h[i])
if(BMI > 25):
count = count + 1
i = i + 1
return count
setup()
Find student BMI.
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [62, 55, 58.2]
height = [1.74, 1.70, 1.73]
BMI(name, weight, height)
def BMI(n, w, h):
i = 0
while(i < len(n)):
BMI = w[i]/(h[i]*h[i])
print(n[i],"BMI =","%.3f"%BMI)
i = i + 1
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [62, 55, 58.2]
height = [1.74, 1.70, 1.73]
BMI(name, weight, height)
def BMI(n, w, h):
i = 0
while(i < len(n)):
BMI = w[i]/(h[i]*h[i])
print(n[i],"BMI =","%.3f"%BMI)
i = i + 1
setup()
Display student records (data).
def setup():
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [62, 55, 58.2]
height = [1.74, 1.70, 1.73]
array(name, ID, age, weight, height)
def array(n, I, a, w, h):
i = 0
while(i < len(n)):
print(n[i], "ID =", I[i], "age =", a[i], "weight =", w[i], "height =", h[i])
i = i + 1
return array
setup()
name = ["Gun", "Rit", "Frame"]
ID = [32075, 32078, 32080]
age = [25, 25, 19]
weight = [62, 55, 58.2]
height = [1.74, 1.70, 1.73]
array(name, ID, age, weight, height)
def array(n, I, a, w, h):
i = 0
while(i < len(n)):
print(n[i], "ID =", I[i], "age =", a[i], "weight =", w[i], "height =", h[i])
i = i + 1
return array
setup()
สมัครสมาชิก:
บทความ (Atom)
Link Video Presentation Resort Managemant System Project.
Video Presentation Resort Managemant System Project. จัดทำโดย พากษ์เสียง: คุณาสิน ทองมณี 5801012620011 ลำดับภาพ: สุพิชชา ศรีศิริ...
-
- 1NF หรือ Fisrt Normal Form มีเงื่อนไขอยู่ว่า ต้องไม่มีคอลลัมน์ใดในตารางที่มีค่ามากกว่า 1 ค่า หรือที่เรียกว่า Atomic ซึ่งหมายถึง ข้อมูลที่...
-
https://docs.google.com/spreadsheets/d/10Y6o-h8dAAKf7MHTtGvQDBJuzGkAx_X0WYVgj2nB8v0/edit?usp=sharing จากภาพจะเห็นว่า - เก...