Assignment 2
https://www.youtube.com/watch?v=PaVoRsUDegw&feature=youtu.be
Computer Fundamental
วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
วันอังคารที่ 24 พฤศจิกายน พ.ศ. 2558
class Student:
def __init__(self,Name,ID,score):
self.name=Name
self.id=ID
self.score=score
def display(self):
print(' '+self.name+' ',self.id,'',self.score)
def get_score(self):
return self.score
def set_score(self,s):
self.score=s
def findGrade(std):
grade=''
score=std.get_score()
if(score >= 80):
grade='A'
elif(score >= 70):
grade='B'
elif(score >= 60):
grade='C'
elif(score >= 50):
grade='D'
else:
grade='F'
return grade
def countGrade(grade,std):
count=0
i=0
while(i<len(std)):
if(findGrade(std[i])== grade):
count+=1
i+=1
return count
def showallgrade(std):
i=0
while(i<len(std)):
std[i].display()
print(findGrade(std[i]))
i+=1
def setup():
std = [Student('top',1,58),
Student('tape',2,80),
Student('tar',3,70),
Student('Q',4,85),
Student('bass',5,50)]
'''std[0].display()'''
findGrade(std[0])
print('countGrade',countGrade('A',std))
print()
showallgrade(std)
setup()
def __init__(self,Name,ID,score):
self.name=Name
self.id=ID
self.score=score
def display(self):
print(' '+self.name+' ',self.id,'',self.score)
def get_score(self):
return self.score
def set_score(self,s):
self.score=s
def findGrade(std):
grade=''
score=std.get_score()
if(score >= 80):
grade='A'
elif(score >= 70):
grade='B'
elif(score >= 60):
grade='C'
elif(score >= 50):
grade='D'
else:
grade='F'
return grade
def countGrade(grade,std):
count=0
i=0
while(i<len(std)):
if(findGrade(std[i])== grade):
count+=1
i+=1
return count
def showallgrade(std):
i=0
while(i<len(std)):
std[i].display()
print(findGrade(std[i]))
i+=1
def setup():
std = [Student('top',1,58),
Student('tape',2,80),
Student('tar',3,70),
Student('Q',4,85),
Student('bass',5,50)]
'''std[0].display()'''
findGrade(std[0])
print('countGrade',countGrade('A',std))
print()
showallgrade(std)
setup()
ลอง run A1 on web but ไม่ทำงาน
scartch it easy to learn programing
scartch it easy to learn programing
วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558
Lab 8 - JAVA
public class Letter {
private String[] T={"######"," # "," # "," # "," # "," # "};
private String[] O={"######","# #","# #","# #","# #","######"};
private String[] P={"######","# #","######","# ","# ","# "};
private String[][] data={T,O,P};
private String word;
private char cha;
public Letter(String word,char cha){
this.word=word;
this.cha=cha;
this.data=data;
}
public void changcha(){
int i=0;
while(i<data.length){
int j=0;
while(j<data[0].length){
data[i][j]=data[i][j].replace('#',cha);
j+=1;
}
i+=1;
}
}
public void display(){
int i=0;
while(i<6){
int j=0;
while(j<word.length()){
if(word.charAt(j)=='T'){
System.out.print(this.data[0][i]);
System.out.print(" ");
}else if(word.charAt(j)=='O'){
System.out.print(this.data[1][i]);
System.out.print(" ");
}else if(word.charAt(j)=='P'){
System.out.print(this.data[2][i]);
System.out.print(" ");
}
j+=1;
}
System.out.println("");
i+=1;
}
}
public static void main(String[] args) {
//String[] word=;
Letter a=new Letter("TOP",'@');
a.changcha();
a.display();
//a.display();
}
}
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
package fffff;
public class Student{
private String name;
private int id;
private int age;
private float weight;
private float height;
private float bmi;
public Student(String name,int id,int age ,float weight,float height){
this.name=name;
this.id=id;
this.age=age;
this.weight=weight;
this.height=height;
}
public void display(){
System.out.print(" "+this.name);
System.out.print(" "+this.id);
System.out.print(" "+this.age);
System.out.print(" "+this.weight);
System.out.println(" "+this.height);
}
public float bmi_st(){
bmi=cal_bmi(weight,height);
this.bmi=bmi;
return bmi;
}
public String get_name(){
return this.name;
}public int get_id(){
return this.id;
}public int get_age(){
return this.age;
}public float get_weight(){
return this.weight;
}public float get_height(){
return this.height;
}public float get_bmi(){
return this.bmi;
}
public static void main(String arg[]){
Student[] std={new Student("top",91,21,80,178),
new Student("tape",32,32,50,175),
new Student("tar",55,18,30,175)};
display(std);
std_bmi(std);
int indexbmi=25;
int countbmi=bmi_morethan(std,indexbmi);
System.out.println(countbmi);
System.out.print(average_st(std));
int indexage=30;
int countage=age_lessthan(std,indexage);
System.out.println(countage);
float mini=minimum_weight(std);
System.out.println(mini);
int indexweight=50;
int countweight=weight_lessthan(std,indexweight);
System.out.println(countweight);
displaylessthan(std,indexweight);
}
public static void display(Student[] s){
int i=0;
while(i<s.length){
s[i].display();
i+=1;
}
}
public static void std_bmi(Student[] s){
int i=0;
while(i<s.length){
s[i].bmi_st();
i+=1;
}
}
public static float cal_bmi(float w,float h){
float bmi=0;
h=h/100;
bmi=w/(h*h);
return bmi;
}
public static int bmi_morethan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_bmi()>max){
s[i].display();
count+=1;
}
i+=1;
}
return count;
}
public static int average_st(Student[] s){
int i=0;
int sum=0;
while(i<s.length){
sum=sum+s[i].get_age();
i+=1;
}
sum=sum/s.length;
return sum;
}
public static int age_lessthan(Student[]s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_age()<max){
count+=1;
}
i+=1;
}
return count;
}
public static float minimum_weight(Student[] s){
int i=1;
float mini=s[0].get_weight();
while(i<s.length){
if(s[i].get_weight()<mini){
mini=s[i].get_weight();
}
i+=1;
}
return mini;
}
public static int weight_lessthan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_weight()<max){
count+=1;
}
i+=1;
}
return count;
}
public static void displaylessthan(Student[] s,int max){
int i=0;
while(i<s.length){
if(s[i].get_weight()<max){
s[i].display();
}
i+=1;
}
}}
private String[] T={"######"," # "," # "," # "," # "," # "};
private String[] O={"######","# #","# #","# #","# #","######"};
private String[] P={"######","# #","######","# ","# ","# "};
private String[][] data={T,O,P};
private String word;
private char cha;
public Letter(String word,char cha){
this.word=word;
this.cha=cha;
this.data=data;
}
public void changcha(){
int i=0;
while(i<data.length){
int j=0;
while(j<data[0].length){
data[i][j]=data[i][j].replace('#',cha);
j+=1;
}
i+=1;
}
}
public void display(){
int i=0;
while(i<6){
int j=0;
while(j<word.length()){
if(word.charAt(j)=='T'){
System.out.print(this.data[0][i]);
System.out.print(" ");
}else if(word.charAt(j)=='O'){
System.out.print(this.data[1][i]);
System.out.print(" ");
}else if(word.charAt(j)=='P'){
System.out.print(this.data[2][i]);
System.out.print(" ");
}
j+=1;
}
System.out.println("");
i+=1;
}
}
public static void main(String[] args) {
//String[] word=;
Letter a=new Letter("TOP",'@');
a.changcha();
a.display();
//a.display();
}
}
mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm
package fffff;
public class Student{
private String name;
private int id;
private int age;
private float weight;
private float height;
private float bmi;
public Student(String name,int id,int age ,float weight,float height){
this.name=name;
this.id=id;
this.age=age;
this.weight=weight;
this.height=height;
}
public void display(){
System.out.print(" "+this.name);
System.out.print(" "+this.id);
System.out.print(" "+this.age);
System.out.print(" "+this.weight);
System.out.println(" "+this.height);
}
public float bmi_st(){
bmi=cal_bmi(weight,height);
this.bmi=bmi;
return bmi;
}
public String get_name(){
return this.name;
}public int get_id(){
return this.id;
}public int get_age(){
return this.age;
}public float get_weight(){
return this.weight;
}public float get_height(){
return this.height;
}public float get_bmi(){
return this.bmi;
}
public static void main(String arg[]){
Student[] std={new Student("top",91,21,80,178),
new Student("tape",32,32,50,175),
new Student("tar",55,18,30,175)};
display(std);
std_bmi(std);
int indexbmi=25;
int countbmi=bmi_morethan(std,indexbmi);
System.out.println(countbmi);
System.out.print(average_st(std));
int indexage=30;
int countage=age_lessthan(std,indexage);
System.out.println(countage);
float mini=minimum_weight(std);
System.out.println(mini);
int indexweight=50;
int countweight=weight_lessthan(std,indexweight);
System.out.println(countweight);
displaylessthan(std,indexweight);
}
public static void display(Student[] s){
int i=0;
while(i<s.length){
s[i].display();
i+=1;
}
}
public static void std_bmi(Student[] s){
int i=0;
while(i<s.length){
s[i].bmi_st();
i+=1;
}
}
public static float cal_bmi(float w,float h){
float bmi=0;
h=h/100;
bmi=w/(h*h);
return bmi;
}
public static int bmi_morethan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_bmi()>max){
s[i].display();
count+=1;
}
i+=1;
}
return count;
}
public static int average_st(Student[] s){
int i=0;
int sum=0;
while(i<s.length){
sum=sum+s[i].get_age();
i+=1;
}
sum=sum/s.length;
return sum;
}
public static int age_lessthan(Student[]s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_age()<max){
count+=1;
}
i+=1;
}
return count;
}
public static float minimum_weight(Student[] s){
int i=1;
float mini=s[0].get_weight();
while(i<s.length){
if(s[i].get_weight()<mini){
mini=s[i].get_weight();
}
i+=1;
}
return mini;
}
public static int weight_lessthan(Student[] s,int max){
int i=0;
int count=0;
while(i<s.length){
if(s[i].get_weight()<max){
count+=1;
}
i+=1;
}
return count;
}
public static void displaylessthan(Student[] s,int max){
int i=0;
while(i<s.length){
if(s[i].get_weight()<max){
s[i].display();
}
i+=1;
}
}}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
Lab 7 studen
class Student:
def __init__(self,name,id,age,weight,height,bmi):
self.name=name
self.id=id
self.age=age
self.weight=weight
self.height=height
self.bmi=bmi
def display(self):
print("Name:",self.name,end=" ")
print("ID:",self.id,end=" ")
print("Age:",self.age,end=" ")
print("Weight:",self.weight,end=" ")
print("Height:",self.height,end=" ")
def bmi_st(self):
bmi=cal_bmi(self.weight,self.height)
self.bmi=bmi
return bmi
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 get_bmi(self):
return self.bmi
def set_bmi(self,bmi):
self.bmi=bmi
def setup():
std=[Student('top',91,21,30,178,0),
Student('tape',32,32,50,175,0),
Student('tar',55,18,49,175,0)]
#display(std)
#std_bmi(std)
#indexbmi=25
#countbmi=bmi_morethan(std,indexbmi)
#print(countbmi)
#average_st(std)
#indexage=30
#countage=age_lessthan(std,indexage)
#print(countage)
#mini=minimum_weight(std)
#print(mini)
#ndexweight=50
#countweight=weight_lessthan(std,indexweight)
#print(countweight)
#displaylessthan(std,indexweight)
def display(s):
i=0
while(i<len(s)):
s[i].display()
print("")
i+=1
def std_bmi(s):
i=0
while(i<len(s)):
s[i].bmi_st()
i+=1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def bmi_morethan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_bmi()>max):
print(s[i].get_name())
count+=1
i+=1
return count
def average_st(s):
i=0
sum=0
while(i<len(s)):
sum=sum+s[i].get_age()
i+=1
sum=sum/len(s)
return sum
def age_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_age()<max):
count+=1
i+=1
return count
def minimum_weight(s):
i=1
mini=s[0].get_weight()
while(i<len(s)):
if(s[i].get_weight()<mini):
mini=s[i].get_weight()
i+=1
return mini
def weight_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_weight()<max):
count+=1
i+=1
return count
def displaylessthan(s,max):
i=0
while(i<len(s)):
if(s[i].get_weight()<max):
print(s[i].get_name())
i+=1
setup()
def __init__(self,name,id,age,weight,height,bmi):
self.name=name
self.id=id
self.age=age
self.weight=weight
self.height=height
self.bmi=bmi
def display(self):
print("Name:",self.name,end=" ")
print("ID:",self.id,end=" ")
print("Age:",self.age,end=" ")
print("Weight:",self.weight,end=" ")
print("Height:",self.height,end=" ")
def bmi_st(self):
bmi=cal_bmi(self.weight,self.height)
self.bmi=bmi
return bmi
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 get_bmi(self):
return self.bmi
def set_bmi(self,bmi):
self.bmi=bmi
def setup():
std=[Student('top',91,21,30,178,0),
Student('tape',32,32,50,175,0),
Student('tar',55,18,49,175,0)]
#display(std)
#std_bmi(std)
#indexbmi=25
#countbmi=bmi_morethan(std,indexbmi)
#print(countbmi)
#average_st(std)
#indexage=30
#countage=age_lessthan(std,indexage)
#print(countage)
#mini=minimum_weight(std)
#print(mini)
#ndexweight=50
#countweight=weight_lessthan(std,indexweight)
#print(countweight)
#displaylessthan(std,indexweight)
def display(s):
i=0
while(i<len(s)):
s[i].display()
print("")
i+=1
def std_bmi(s):
i=0
while(i<len(s)):
s[i].bmi_st()
i+=1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def bmi_morethan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_bmi()>max):
print(s[i].get_name())
count+=1
i+=1
return count
def average_st(s):
i=0
sum=0
while(i<len(s)):
sum=sum+s[i].get_age()
i+=1
sum=sum/len(s)
return sum
def age_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_age()<max):
count+=1
i+=1
return count
def minimum_weight(s):
i=1
mini=s[0].get_weight()
while(i<len(s)):
if(s[i].get_weight()<mini):
mini=s[i].get_weight()
i+=1
return mini
def weight_lessthan(s,max):
i=0
count=0
while(i<len(s)):
if(s[i].get_weight()<max):
count+=1
i+=1
return count
def displaylessthan(s,max):
i=0
while(i<len(s)):
if(s[i].get_weight()<max):
print(s[i].get_name())
i+=1
setup()
Lab 7 letter
class Letter:
def __init__(self,word,data,char):
self.word=word
self.data=data
self.char=char
def display(self):
i=0
while(i<6):
j=0
while(j<len(self.word)):
if(self.word[j]=='T'):
print(self.data[0][i],end=" ")
elif(self.word[j]=='O'):
print(self.data[1][i],end=" ")
elif(self.word[j]=='P'):
print(self.data[2][i],end=" ")
j+=1
print(" ")
i+=1
def setup():
T=['######',' # ',' # ',' # ',' # ',' # ']
O=['######','# #','# #','# #','# #','######']
P=['######','# #','######','# ','# ','# ']
data=[T,O,P]
word='TPO'
showLetter= Letter(word,data,'*')
showLetter.display()
setup()
def __init__(self,word,data,char):
self.word=word
self.data=data
self.char=char
def display(self):
i=0
while(i<6):
j=0
while(j<len(self.word)):
if(self.word[j]=='T'):
print(self.data[0][i],end=" ")
elif(self.word[j]=='O'):
print(self.data[1][i],end=" ")
elif(self.word[j]=='P'):
print(self.data[2][i],end=" ")
j+=1
print(" ")
i+=1
def setup():
T=['######',' # ',' # ',' # ',' # ',' # ']
O=['######','# #','# #','# #','# #','######']
P=['######','# #','######','# ','# ','# ']
data=[T,O,P]
word='TPO'
showLetter= Letter(word,data,'*')
showLetter.display()
setup()
วันจันทร์ที่ 19 ตุลาคม พ.ศ. 2558
lab6
def setup():
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",countBmi)
def find_BmiHeight25(bmi):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
#height25[i]=
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def setup():
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
#countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",find_BmiHeight25(bmi,name))
def find_BmiHeight25(bmi,n):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
print("Name ",n[i])
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",countBmi)
def find_BmiHeight25(bmi):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
#height25[i]=
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
def setup():
name=['top','tape','bass']
st_id=[15,16,17]
age=[17,18,18]
weight=[83,93,69]
height=[178,175,175]
bmi=[None]*3
bmical(weight,height,bmi)
display(name,st_id,age,weight,height,bmi)
print("-----------------------")
#countBmi=find_BmiHeight25(bmi)
print("Bmi > 25 : ",find_BmiHeight25(bmi,name))
def find_BmiHeight25(bmi,n):
i=0
count=0
maximum=25;
while(i<len(bmi)):
if(bmi[i]>maximum):
maximum=bmi[i]
print("Name ",n[i])
count=count+1
i=i+1
return count
def bmical(w,h,bmi):
i=0
while(i<len(bmi)):
bmi[i]=cal_bmi(w[i],h[i])
i=i+1
def cal_bmi(w,h):
bmi=0
h=h/100
bmi=w/(h*h)
return bmi
def display(n,st_id,a,w,h,bmi):
i=0
while(i<len(n)):
print("Name ",n[i]," St_id ",st_id[i]," Age ",a[i]," Weight ",w[i]," height ",h[i]," Bmi ",bmi[i])
i=i+1
setup()
วันจันทร์ที่ 28 กันยายน พ.ศ. 2558
binary
def binary():
n=18
c=0
b=""
s=""
while(n>0):
b=n%2
c=n%2
if(b==1):
b="1"
elif(b==0):
b="0"
s=b+s
n=(n-c)/2
return s
binary()
print(binary())
n=18
c=0
b=""
s=""
while(n>0):
b=n%2
c=n%2
if(b==1):
b="1"
elif(b==0):
b="0"
s=b+s
n=(n-c)/2
return s
binary()
print(binary())
สมัครสมาชิก:
บทความ (Atom)