วันเสาร์ที่ 5 ธันวาคม พ.ศ. 2558
วันอังคารที่ 24 พฤศจิกายน พ.ศ. 2558
report raspberry pi
The raspberry pi is too slow sometimes cannot use the
internet. When coding it too slow. It cannot change the
language.
internet. When coding it too slow. It cannot change the
language.
lab raspberry pi
class Student:
def __init__(self,name,ID,score):
self.name = name
self.score = score
self.ID = ID
def get_name(self):
return self.name
def get_score(self):
return self.score
def get_ID(self):
return self.ID
def display_data(self):
print('Name',self.name)
print('ID',self.ID)
print('score',self.score)
def caculation_gragd(data,index):
print('Grade :' ,end = ' ')
if(data[index].get_score() >= 80 ):
print('A')
elif(data[index].get_score() >=70 ):
print('B')
elif(data[index].get_score() >=60 ):
print('C')
elif(data[index].get_score() >=50 ):
print('D')
elif(data[index].get_score() < 50 ):
print('F')
def count_grad_a(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 80):
count += 1
index = index + 1
return count
def count_grad_b(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 70 and data[index].get_score() <= 79):
count += 1
index = index + 1
return count
def count_grad_c(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 59 and data[index].get_score() <= 69):
count += 1
index = index + 1
return count
def count_grad_d(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 50 and data[index].get_score()<= 58 ):
count += 1
index = index + 1
return count
def count_grad_f(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() < 50):
count += 1
index = index + 1
return count
def show_each_grade(data,ID):
index = -1
find = False
while(index<len(data) and not (find)):
if(data[index].get_ID() == ID):
find = True
index = index + 1
index -= 1
if(data[index].get_score() >= 80 ):
grade = 'A'
elif(data[index].get_score() >=70 ):
grade = 'B'
elif(data[index].get_score() >=60 ):
grade = 'C'
elif(data[index].get_score() >=50 ):
grade = 'D'
elif(data[index].get_score() < 50 ):
grade = 'F'
print('NAME ',data[index].get_name())
print('SCORE ',data[index].get_score())
print('GRADE ',grade)
def setup():
index = 0
data = [Student('ant',1,60),
Student('bird',2,70),
Student('cat',3,81),
Student('dog',4,78),
Student('fish',5,56)]
while(index<len(data)):
data[index].display_data()
caculation_gragd(data,index)
index = index + 1
print('Grade A ',count_grad_a(data))
print('Grade B ',count_grad_b(data))
print('Grade C ',count_grad_c(data))
print('Grade D ',count_grad_d(data))
print('Grade F ',count_grad_f(data))
show_each_grade(data,3)
setup()
def __init__(self,name,ID,score):
self.name = name
self.score = score
self.ID = ID
def get_name(self):
return self.name
def get_score(self):
return self.score
def get_ID(self):
return self.ID
def display_data(self):
print('Name',self.name)
print('ID',self.ID)
print('score',self.score)
def caculation_gragd(data,index):
print('Grade :' ,end = ' ')
if(data[index].get_score() >= 80 ):
print('A')
elif(data[index].get_score() >=70 ):
print('B')
elif(data[index].get_score() >=60 ):
print('C')
elif(data[index].get_score() >=50 ):
print('D')
elif(data[index].get_score() < 50 ):
print('F')
def count_grad_a(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 80):
count += 1
index = index + 1
return count
def count_grad_b(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 70 and data[index].get_score() <= 79):
count += 1
index = index + 1
return count
def count_grad_c(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 59 and data[index].get_score() <= 69):
count += 1
index = index + 1
return count
def count_grad_d(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() >= 50 and data[index].get_score()<= 58 ):
count += 1
index = index + 1
return count
def count_grad_f(data):
index = 0
count = 0
while(index<len(data)):
if(data[index].get_score() < 50):
count += 1
index = index + 1
return count
def show_each_grade(data,ID):
index = -1
find = False
while(index<len(data) and not (find)):
if(data[index].get_ID() == ID):
find = True
index = index + 1
index -= 1
if(data[index].get_score() >= 80 ):
grade = 'A'
elif(data[index].get_score() >=70 ):
grade = 'B'
elif(data[index].get_score() >=60 ):
grade = 'C'
elif(data[index].get_score() >=50 ):
grade = 'D'
elif(data[index].get_score() < 50 ):
grade = 'F'
print('NAME ',data[index].get_name())
print('SCORE ',data[index].get_score())
print('GRADE ',grade)
def setup():
index = 0
data = [Student('ant',1,60),
Student('bird',2,70),
Student('cat',3,81),
Student('dog',4,78),
Student('fish',5,56)]
while(index<len(data)):
data[index].display_data()
caculation_gragd(data,index)
index = index + 1
print('Grade A ',count_grad_a(data))
print('Grade B ',count_grad_b(data))
print('Grade C ',count_grad_c(data))
print('Grade D ',count_grad_d(data))
print('Grade F ',count_grad_f(data))
show_each_grade(data,3)
setup()
วันอาทิตย์ที่ 15 พฤศจิกายน พ.ศ. 2558
lab 8 bannner by java
public class Banner {
private String word;
private char font;
public Banner(String word, char font) {
this.word = word;
this.font = font;
}
public void display() {
String a1 = " ######## ";
String a2 = " ## ## ";
String a3 = " ## ## ";
String a4 = " ######## ";
String a5 = " ## ## ";
String[] letter_a = {a1, a2, a3, a4, a5};
String n1 = " ## ## ";
String n2 = " ## # ## ";
String n3 = " ## # ## ";
String n4 = " ## # ## ";
String n5 = " ## ## ";
String[] letter_n = {n1, n2, n3, n4, n5};
String t1 = " ########## ";
String t2 = " ## ";
String t3 = " ## ";
String t4 = " ## ";
String t5 = " ## ";
String[] letter_t = {t1, t2, t3, t4, t5};
int index_a = 0;
change_font(letter_a, '#', this.font);
change_font(letter_n, '#', this.font);
change_font(letter_t, '#', this.font);
while (index_a < 5) {
int index_n = 0;
while (index_n < this.word.length()) {
if (this.word.charAt(index_n) == 'A') {
System.out.print(letter_a[index_a]);
} else if (this.word.charAt(index_n) == 'N') {
System.out.print(letter_n[index_a]);
} else if (this.word.charAt(index_n) == 'T') {
System.out.print(letter_t[index_a]);
}
index_n = index_n + 1;
}
System.out.println();
index_a = index_a + 1;
}
}
public void set_font(char font) {
this.font = font;
}
public static void main(String[] args) {
String word = "ANT";
Banner B = new Banner(word, '#');
B.display();
B.set_font('O');
B.display();
}
public static void change_font(String[] letter, char font, char last_font) {
int index = 0;
while (index < letter.length) {
String change_font = "";
int index2 = 0;
while (index2 < letter[index].length()) {
if (letter[index].charAt(index2) == font) {
change_font += last_font;
} else {
change_font += " ";
}
index2 += 1;
}
letter[index] = change_font;
index += 1;
}
}
}
วันอาทิตย์ที่ 8 พฤศจิกายน พ.ศ. 2558
lab 8 display age by sort (java)
public class Student {
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public String get_name(){
return this.name;
}
public int get_weight(){
return this.weight;
}
public int get_high(){
return this.high;
}
public int get_age(){
return this.age;
}
public int get_ID(){
return this.ID;
}
public void set_name(String value){
this.name = value;
}
public void set_weight(int value){
this.weight = value;
}
public void set_high(int value){
this.high = value;
}
public void set_age(int value){
this.age = value;
}
public void set_ID(int value){
this.ID = value;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
sort_age(std);
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
}
public static void sort_age(Student[] std){
int index = 1 ;
while(index<std.length){
String value_name = std[index].get_name();
int value_weight = std[index].get_weight();
int value_high = std[index].get_high();
int value_age = std[index].get_age();
int value_ID = std[index].get_ID();
int pos = index ;
while(pos>0 &&std[pos - 1].get_age()>value_age){
std[pos].set_name(std[pos - 1].get_name());
std[pos].set_weight(std[pos - 1].get_weight());
std[pos].set_high(std[pos - 1].get_high());
std[pos].set_age(std[pos - 1].get_age());
std[pos].set_ID(std[pos - 1].get_ID());
pos = pos - 1;
}
if(pos != index){
std[pos].set_name(value_name);
std[pos].set_weight(value_weight);
std[pos].set_high(value_high);
std[pos].set_age(value_age);
std[pos].set_ID(value_ID);
}
index = index + 1;
}
}
}
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public String get_name(){
return this.name;
}
public int get_weight(){
return this.weight;
}
public int get_high(){
return this.high;
}
public int get_age(){
return this.age;
}
public int get_ID(){
return this.ID;
}
public void set_name(String value){
this.name = value;
}
public void set_weight(int value){
this.weight = value;
}
public void set_high(int value){
this.high = value;
}
public void set_age(int value){
this.age = value;
}
public void set_ID(int value){
this.ID = value;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
sort_age(std);
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
}
public static void sort_age(Student[] std){
int index = 1 ;
while(index<std.length){
String value_name = std[index].get_name();
int value_weight = std[index].get_weight();
int value_high = std[index].get_high();
int value_age = std[index].get_age();
int value_ID = std[index].get_ID();
int pos = index ;
while(pos>0 &&std[pos - 1].get_age()>value_age){
std[pos].set_name(std[pos - 1].get_name());
std[pos].set_weight(std[pos - 1].get_weight());
std[pos].set_high(std[pos - 1].get_high());
std[pos].set_age(std[pos - 1].get_age());
std[pos].set_ID(std[pos - 1].get_ID());
pos = pos - 1;
}
if(pos != index){
std[pos].set_name(value_name);
std[pos].set_weight(value_weight);
std[pos].set_high(value_high);
std[pos].set_age(value_age);
std[pos].set_ID(value_ID);
}
index = index + 1;
}
}
}
วันเสาร์ที่ 7 พฤศจิกายน พ.ศ. 2558
lab 8 find count age that less than 30 years old and average age by java
public class Student {
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public int get_age(){
return this.age;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
System.out.println("Average age is "+average_age(std)+" years old");
System.out.println("The number of students that have age less than 30 years old is "+count_age(std));
}
public static float average_age(Student[] std){
int index = 0;
float sum_age = 0;
float age = 0;
while(index<std.length){
sum_age += std[index].get_age();
index = index + 1;
}
age = (sum_age)/5 ;
return age;
}
public static int count_age(Student[] std){
int index = 0 ;
int count = 0;
while(index<std.length){
if(std[index].get_age()<30){
count +=1;
}
index = index + 1;
}
return count ;
}
}
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public int get_age(){
return this.age;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
System.out.println("Average age is "+average_age(std)+" years old");
System.out.println("The number of students that have age less than 30 years old is "+count_age(std));
}
public static float average_age(Student[] std){
int index = 0;
float sum_age = 0;
float age = 0;
while(index<std.length){
sum_age += std[index].get_age();
index = index + 1;
}
age = (sum_age)/5 ;
return age;
}
public static int count_age(Student[] std){
int index = 0 ;
int count = 0;
while(index<std.length){
if(std[index].get_age()<30){
count +=1;
}
index = index + 1;
}
return count ;
}
}
lab 8 find count and display the minimum weight by java
public class Student {
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name ,int weight , int high , int age , int ID) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public int get_weight(){
return this.weight;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)
};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
System.out.println("The number of students that have weight less than 50 kg. is "+count_weight(std));
System.out.println( "The minimum weight is " +find_minimum_weight( std)+" kg. ");
}
public static int count_weight(Student[] std){
int index = 0 ;
int count = 0 ;
while(index<std.length){
if(std[index].get_weight()<50){
count +=1 ;
}
index = index + 1 ;
}
return count ;
}
public static int find_minimum_weight(Student[] std){
int index = 0;
int weight = 100;
while(index<std.length){
if(std[index].get_weight()<weight){
weight = std[index].get_weight();
}
index = index + 1;
}
return weight;
}
}
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name ,int weight , int high , int age , int ID) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public int get_weight(){
return this.weight;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)
};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
System.out.println("The number of students that have weight less than 50 kg. is "+count_weight(std));
System.out.println( "The minimum weight is " +find_minimum_weight( std)+" kg. ");
}
public static int count_weight(Student[] std){
int index = 0 ;
int count = 0 ;
while(index<std.length){
if(std[index].get_weight()<50){
count +=1 ;
}
index = index + 1 ;
}
return count ;
}
public static int find_minimum_weight(Student[] std){
int index = 0;
int weight = 100;
while(index<std.length){
if(std[index].get_weight()<weight){
weight = std[index].get_weight();
}
index = index + 1;
}
return weight;
}
}
วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558
lab 8 calculation of bmi by lava
public class Student {
private String name;
private float weight;
private float high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public float get_high(){
return this.high;
}
public float get_weight(){
return this.weight;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)
};
int index = 0;
while(index<std.length){
std[index].display();
System.out.println("BMI "+calculation_of_bmi (std[index] ));
index = index + 1;
}
System.out.println("Number of students that have bmi more than 25 is "+count_bmi(std));
}
public static float calculation_of_bmi (Student Student){
float highM = Student.get_high() / 100;
float bmi = Student.get_weight()/(highM*highM);
return bmi ;
}
public static int count_bmi(Student[] student){
int index = 0 ;
int count = 0 ;
while(index<student.length){
if(calculation_of_bmi (student[index])>25){
count +=1 ;
}
index = index + 1 ;
}
return count ;
}
}
private String name;
private float weight;
private float high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public float get_high(){
return this.high;
}
public float get_weight(){
return this.weight;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)
};
int index = 0;
while(index<std.length){
std[index].display();
System.out.println("BMI "+calculation_of_bmi (std[index] ));
index = index + 1;
}
System.out.println("Number of students that have bmi more than 25 is "+count_bmi(std));
}
public static float calculation_of_bmi (Student Student){
float highM = Student.get_high() / 100;
float bmi = Student.get_weight()/(highM*highM);
return bmi ;
}
public static int count_bmi(Student[] student){
int index = 0 ;
int count = 0 ;
while(index<student.length){
if(calculation_of_bmi (student[index])>25){
count +=1 ;
}
index = index + 1 ;
}
return count ;
}
}
lab 8 data by java
public class Student {
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
}
}
private String name;
private int weight;
private int high;
private int age;
private int ID;
public Student(String name , int weight , int high , int age , int ID ) {
this.name = name ;
this.weight = weight;
this.high = high;
this.age = age;
this.ID = ID;
}
public void display() {
System.out.println( "NAME: "+this.name);
System.out.println( "WEIGHT:"+this.weight+" kg.");
System.out.println( "HIGH:"+this.high+" cm.");
System.out.println( "AGE :"+this.age+" years old");
System.out.println( "ID :"+this.ID);
}
public static void main(String[] args) {
Student[] std = {new Student("Park",40,160,18,1),
new Student("Nani",50,180,19,2),
new Student("Pepe",80,185,20,3),
new Student("Giggs",70,160,18,4),
new Student("Laws",85,155,18,5)};
int index = 0;
while(index<std.length){
std[index].display();
index = index + 1;
}
}
}
lab 7 string
class letter():
def __init__(self,word,font):
self.word = word
self.font = font
def display(self):
a1 = " ######## "
a2 = " ## ## "
a3 = " ## ## "
a4 = " ######## "
a5 = " ## ## "
letter_a = [a1,a2,a3,a4,a5]
n1 = " ## ## "
n2 = " ## # ## "
n3 = " ## # ## "
n4 = " ## # ## "
n5 = " ## ## "
letter_n = [n1,n2,n3,n4,n5]
t1 = " ########## "
t2 = " ## "
t3 = " ## "
t4 = " ## "
t5 = " ## "
letter_t = [t1,t2,t3,t4,t5]
index_a = 0
change_font(letter_a,"#",self.font)
change_font(letter_n,"#",self.font)
change_font(letter_t,"#",self.font)
while(index_a < 5):
index_n = 0
while(index_n < len(self.word)):
if(self.word[index_n]=="A"):
print(letter_a[index_a], end =" ")
elif(self.word[index_n] =="N"):
print(letter_n[index_a], end = " ")
elif(self.word[index_n] =="T"):
print(letter_t[index_a], end = " ")
index_n = index_n + 1
print()
index_a = index_a + 1
def set_font(self,font):
self.font = font
def setup():
word = "ANT"
B = letter(word,"#")
B.display()
B.set_font("*")
B.display()
def change_font(letter,font,last_font):
index = 0
while(index<len(letter)):
change_font = ""
index2 = 0
while(index2<len(letter[index])):
if(letter[index][index2] == font):
change_font += last_font
else:
change_font += " "
index2 += 1
letter[index] = change_font
index += 1
setup()
def __init__(self,word,font):
self.word = word
self.font = font
def display(self):
a1 = " ######## "
a2 = " ## ## "
a3 = " ## ## "
a4 = " ######## "
a5 = " ## ## "
letter_a = [a1,a2,a3,a4,a5]
n1 = " ## ## "
n2 = " ## # ## "
n3 = " ## # ## "
n4 = " ## # ## "
n5 = " ## ## "
letter_n = [n1,n2,n3,n4,n5]
t1 = " ########## "
t2 = " ## "
t3 = " ## "
t4 = " ## "
t5 = " ## "
letter_t = [t1,t2,t3,t4,t5]
index_a = 0
change_font(letter_a,"#",self.font)
change_font(letter_n,"#",self.font)
change_font(letter_t,"#",self.font)
while(index_a < 5):
index_n = 0
while(index_n < len(self.word)):
if(self.word[index_n]=="A"):
print(letter_a[index_a], end =" ")
elif(self.word[index_n] =="N"):
print(letter_n[index_a], end = " ")
elif(self.word[index_n] =="T"):
print(letter_t[index_a], end = " ")
index_n = index_n + 1
print()
index_a = index_a + 1
def set_font(self,font):
self.font = font
def setup():
word = "ANT"
B = letter(word,"#")
B.display()
B.set_font("*")
B.display()
def change_font(letter,font,last_font):
index = 0
while(index<len(letter)):
change_font = ""
index2 = 0
while(index2<len(letter[index])):
if(letter[index][index2] == font):
change_font += last_font
else:
change_font += " "
index2 += 1
letter[index] = change_font
index += 1
setup()
lab 7 display data sort by age
class student():
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_age(self):
return self.age
def get_name(self):
return self.name
def get_weight(self):
return self.weight
def get_high(self):
return self.high
def get_ID(self):
return self.ID
def set_age(self,value):
self.age = value
def set_name(self,value):
self.name = value
def set_weight(self,value):
self.weight = value
def set_high(self,value):
self.high = value
def set_ID(self,value):
self.ID = value
def sort_insertion(data):
index = 1
while(index<len(data)):
value_age = data[index].get_age()
value_name = data[index].get_name()
value_weight = data[index].get_weight()
value_high = data[index].get_high()
value_ID = data[index].get_ID()
pos = index
while((pos>0)and (data[pos - 1].get_age()>value_age)):
data[pos].set_age(data[pos - 1].get_age())
data[pos].set_name(data[pos - 1].get_name())
data[pos].set_weight(data[pos - 1].get_weight())
data[pos].set_high(data[pos - 1].get_high())
data[pos].set_ID(data[pos - 1].get_ID())
pos = pos - 1
if(pos !=index):
data[pos].set_age(value_age)
data[pos].set_name(value_name)
data[pos].set_weight(value_weight)
data[pos].set_high(value_high)
data[pos].set_ID(value_ID)
index = index +1
return data
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
sort_insertion(data)
while(index<len(data)):
data[index].show_data()
index = index + 1
setup()
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_age(self):
return self.age
def get_name(self):
return self.name
def get_weight(self):
return self.weight
def get_high(self):
return self.high
def get_ID(self):
return self.ID
def set_age(self,value):
self.age = value
def set_name(self,value):
self.name = value
def set_weight(self,value):
self.weight = value
def set_high(self,value):
self.high = value
def set_ID(self,value):
self.ID = value
def sort_insertion(data):
index = 1
while(index<len(data)):
value_age = data[index].get_age()
value_name = data[index].get_name()
value_weight = data[index].get_weight()
value_high = data[index].get_high()
value_ID = data[index].get_ID()
pos = index
while((pos>0)and (data[pos - 1].get_age()>value_age)):
data[pos].set_age(data[pos - 1].get_age())
data[pos].set_name(data[pos - 1].get_name())
data[pos].set_weight(data[pos - 1].get_weight())
data[pos].set_high(data[pos - 1].get_high())
data[pos].set_ID(data[pos - 1].get_ID())
pos = pos - 1
if(pos !=index):
data[pos].set_age(value_age)
data[pos].set_name(value_name)
data[pos].set_weight(value_weight)
data[pos].set_high(value_high)
data[pos].set_ID(value_ID)
index = index +1
return data
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
sort_insertion(data)
while(index<len(data)):
data[index].show_data()
index = index + 1
setup()
lab 7 display average,display find and count age that less than 30
class student():
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_age(self):
return self.age
def age(data):
age = data.get_age()
return age
def average_age(data):
index = 0
summation = 0
while(index<len(data)):
summation += age(data[index])/4
index = index + 1
return summation
def find_age(data):
index = 0
while(index<len(data)):
if(age(data[index])<30):
print(age(data[index]),end = " ")
index = index + 1
def count_age(data):
index = 0
count = 0
while(index<len(data)):
if(age(data[index])<30):
count +=1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
index = index + 1
print("Average age is",average_age(data),"years old")
print("Display the age that under 30 years old")
find_age(data)
print()
print("The number of age that under 30 years old is",count_age(data))
setup()
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_age(self):
return self.age
def age(data):
age = data.get_age()
return age
def average_age(data):
index = 0
summation = 0
while(index<len(data)):
summation += age(data[index])/4
index = index + 1
return summation
def find_age(data):
index = 0
while(index<len(data)):
if(age(data[index])<30):
print(age(data[index]),end = " ")
index = index + 1
def count_age(data):
index = 0
count = 0
while(index<len(data)):
if(age(data[index])<30):
count +=1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
index = index + 1
print("Average age is",average_age(data),"years old")
print("Display the age that under 30 years old")
find_age(data)
print()
print("The number of age that under 30 years old is",count_age(data))
setup()
lab 7 find minimum weight, find count and displat weight that < 50
class student():
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_weight(self):
return self.weight
def weight(data):
weight = data.get_weight()
return weight
def find_minimum_weight(data):
index = 0
minimum =100
while(index<len(data)):
if(weight(data[index])< minimum):
minimum = weight(data[index])
index = index + 1
return minimum
def show_weight(data):
index = 0
while(index<len(data)):
if(weight(data[index])<50):
print(weight(data[index]),end = " ")
index = index + 1
def count_weight(data):
index = 0
count = 0
while(index<len(data)):
if(weight(data[index])<50):
count += 1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
index = index + 1
print("Display the weight that less than 50 kg.")
show_weight(data)
print()
print("Number of students that have weight less than 50 kg. is ",count_weight(data))
print("The minimum weight is ",find_minimum_weight(data),"kg.")
setup()
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_weight(self):
return self.weight
def weight(data):
weight = data.get_weight()
return weight
def find_minimum_weight(data):
index = 0
minimum =100
while(index<len(data)):
if(weight(data[index])< minimum):
minimum = weight(data[index])
index = index + 1
return minimum
def show_weight(data):
index = 0
while(index<len(data)):
if(weight(data[index])<50):
print(weight(data[index]),end = " ")
index = index + 1
def count_weight(data):
index = 0
count = 0
while(index<len(data)):
if(weight(data[index])<50):
count += 1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
index = index + 1
print("Display the weight that less than 50 kg.")
show_weight(data)
print()
print("Number of students that have weight less than 50 kg. is ",count_weight(data))
print("The minimum weight is ",find_minimum_weight(data),"kg.")
setup()
lab 7 display data , find count bmi >25 and display bmi
class student():
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_weight(self):
return self.weight
def get_high(self):
return self.high
def calculation(data):
highM = data.get_high()/100
bmi = data.get_weight()/(highM*highM)
return bmi
def find_bmi(data):
index = 0
count = 0
while(index<len(data)):
if(calculation(data[index])>25):
count +=1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
print("BMI ",calculation(data[index]))
index = index + 1
print("The number of student that have bmi more than 25 is ",find_bmi(data))
setup()
def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_weight(self):
return self.weight
def get_high(self):
return self.high
def calculation(data):
highM = data.get_high()/100
bmi = data.get_weight()/(highM*highM)
return bmi
def find_bmi(data):
index = 0
count = 0
while(index<len(data)):
if(calculation(data[index])>25):
count +=1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
print("BMI ",calculation(data[index]))
index = index + 1
print("The number of student that have bmi more than 25 is ",find_bmi(data))
setup()
วันจันทร์ที่ 26 ตุลาคม พ.ศ. 2558
lab 7 display BMI
def setup():
a = student("Giggs",20,180,60)
b = student("Keane",18,165,90)
c = student("Cole",21,185,74)
d = student("Scholes",19,177,55)
e = student("Park",18,175,46)
a.show()
b.show()
c.show()
d.show()
e.show()
print('BMI of',a.get_name(),calculation_of_bmi(a))
print('BMI of',b.get_name(),calculation_of_bmi(b))
print('BMI of',c.get_name(),calculation_of_bmi(c))
print('BMI of',d.get_name(),calculation_of_bmi(d))
print('BMI of',e.get_name(),calculation_of_bmi(e))
def calculation_of_bmi(student):
highM = student.get_high()/100
bmi = student.get_weight()/(highM*highM)
return bmi
class student:
def __init__(self,name,age,high,weight):
self.name = name
self.age = age
self.weight = weight
self.high = high
def show(self):
print(self.name, end = " ")
print(self.age, end = " ")
print(self.weight, end = " ")
print(self.high, end = " ")
print()
def get_weight(self):
return self.weight
def get_high(self):
return self.high
def get_name(self):
return self.name
setup()
a = student("Giggs",20,180,60)
b = student("Keane",18,165,90)
c = student("Cole",21,185,74)
d = student("Scholes",19,177,55)
e = student("Park",18,175,46)
a.show()
b.show()
c.show()
d.show()
e.show()
print('BMI of',a.get_name(),calculation_of_bmi(a))
print('BMI of',b.get_name(),calculation_of_bmi(b))
print('BMI of',c.get_name(),calculation_of_bmi(c))
print('BMI of',d.get_name(),calculation_of_bmi(d))
print('BMI of',e.get_name(),calculation_of_bmi(e))
def calculation_of_bmi(student):
highM = student.get_high()/100
bmi = student.get_weight()/(highM*highM)
return bmi
class student:
def __init__(self,name,age,high,weight):
self.name = name
self.age = age
self.weight = weight
self.high = high
def show(self):
print(self.name, end = " ")
print(self.age, end = " ")
print(self.weight, end = " ")
print(self.high, end = " ")
print()
def get_weight(self):
return self.weight
def get_high(self):
return self.high
def get_name(self):
return self.name
setup()
วันอาทิตย์ที่ 25 ตุลาคม พ.ศ. 2558
lab 7 display name age weight and high
def setup():
a = student("Giggs",20,180,60)
b = student("Keane",18,165,90)
c = student("Cole",21,185,74)
d = student("Scholes",19,177,55)
e = student("Park",18,175,46)
a.show()
b.show()
c.show()
d.show()
e.show()
class student:
def __init__(self,name,age,weight,high):
self.name = name
self.age = age
self.weight = weight
self.high = high
def show(self):
print(self.name, end = " ")
print(self.age, end = " ")
print(self.weight, end = " ")
print(self.high, end = " ")
print()
setup()
a = student("Giggs",20,180,60)
b = student("Keane",18,165,90)
c = student("Cole",21,185,74)
d = student("Scholes",19,177,55)
e = student("Park",18,175,46)
a.show()
b.show()
c.show()
d.show()
e.show()
class student:
def __init__(self,name,age,weight,high):
self.name = name
self.age = age
self.weight = weight
self.high = high
def show(self):
print(self.name, end = " ")
print(self.age, end = " ")
print(self.weight, end = " ")
print(self.high, end = " ")
print()
setup()
lab 6 sort age
def setup():
age = [35,19,18,20,19,31]
print(age)
print('Display the age that less than 30 years old by sort age')
sort_age(age)
show_age(age)
def show_age(age):
count = 0
find_age = 30
while(count<len(age)):
if(age[count]<find_age):
print(age[count])
count = count + 1
def sort_age(age):
index =1
while(index<len(age)):
new_age =age[index]
index2=index
while(index2>0 and age[index2-1]>new_age):
age[index2]=age[index2-1]
index2=index2-1
age[index2]=new_age
index=index+1
setup()
age = [35,19,18,20,19,31]
print(age)
print('Display the age that less than 30 years old by sort age')
sort_age(age)
show_age(age)
def show_age(age):
count = 0
find_age = 30
while(count<len(age)):
if(age[count]<find_age):
print(age[count])
count = count + 1
def sort_age(age):
index =1
while(index<len(age)):
new_age =age[index]
index2=index
while(index2>0 and age[index2-1]>new_age):
age[index2]=age[index2-1]
index2=index2-1
age[index2]=new_age
index=index+1
setup()
lab 6 multiply
def setup():
row_11=[20,15]
row_12=[37,3]
matrix1=[row_11,row_12]
row_21=[4,16]
row_22=[51,34]
matrix2=[row_21,row_22]
multiply_matrix(matrix1,matrix2)
def multiply_matrix(matrix1,matrix2):
index=0
index2=0
k=0
add1=0
add2=0
multiply=0
while(index<len(matrix1)):
print("|",end=" ")
while(index2<len(matrix1)):
add1 = matrix1[index][k]*matrix2[k][index2]
add2 = matrix1[index][k+1]*matrix2[k+1][index2]
multiply = add1+add2
print(multiply,end=" ")
index2 = index2 + 1
index2 = 0
print("|")
index = index+1
setup()
row_11=[20,15]
row_12=[37,3]
matrix1=[row_11,row_12]
row_21=[4,16]
row_22=[51,34]
matrix2=[row_21,row_22]
multiply_matrix(matrix1,matrix2)
def multiply_matrix(matrix1,matrix2):
index=0
index2=0
k=0
add1=0
add2=0
multiply=0
while(index<len(matrix1)):
print("|",end=" ")
while(index2<len(matrix1)):
add1 = matrix1[index][k]*matrix2[k][index2]
add2 = matrix1[index][k+1]*matrix2[k+1][index2]
multiply = add1+add2
print(multiply,end=" ")
index2 = index2 + 1
index2 = 0
print("|")
index = index+1
setup()
lab 6 find chairs
def setup():
floor_one = [10,25,30,55]
floor_two = [25,65,20,30]
floor_three = [15,25,40,45]
building = [floor_one,floor_two,floor_three]
print('Floor one has',totol_chairs(floor_one),'chairs')
print('Floor two has',totol_chairs(floor_two),'chairs')
print('floor three has',totol_chairs(floor_three),'chairs')
print('Total chairs are',total_chairs(building))
print('The number of maximum Chairs are in floor',max_floor(building))
print('The class that have maximum chairs is',find_max_class(building),'chairs')
def totol_chairs(floor_one):
index = 0
sum= 0
while(index < len(floor_one)):
sum += floor_one[index]
index += 1
return sum
def totol_chairs(floor_two):
index = 0
sum= 0
while(index < len(floor_two)):
sum += floor_two[index]
index += 1
return sum
def totol_chairs(floor_three):
index = 0
sum= 0
while(index < len(floor_three)):
sum += floor_three[index]
index += 1
return sum
def total_chairs(building):
allchairs = 0
index = 0
while(index<len(building)):
j = 0
while(j<len(building[index])):
allchairs = allchairs + building[index][j]
j = j + 1
index = index + 1
return allchairs
def max_floor(building):
max_floor = 0
index = 0
while(index<len(building)):
summation = 0
j = 0
while(j<len(building[index])):
summation = summation + building[index][j]
j = j + 1
if(summation>max_floor):
max_floor = index
index = index + 1
return max_floor
def find_max_class(building):
maximum = 0
index = 0
while(index < len(building)):
j = 0
while(j < len(building[index])):
if(building[index][j] > maximum):
maximum = building[index][j]
j = j + 1
index = index + 1
return maximum
setup()
floor_one = [10,25,30,55]
floor_two = [25,65,20,30]
floor_three = [15,25,40,45]
building = [floor_one,floor_two,floor_three]
print('Floor one has',totol_chairs(floor_one),'chairs')
print('Floor two has',totol_chairs(floor_two),'chairs')
print('floor three has',totol_chairs(floor_three),'chairs')
print('Total chairs are',total_chairs(building))
print('The number of maximum Chairs are in floor',max_floor(building))
print('The class that have maximum chairs is',find_max_class(building),'chairs')
def totol_chairs(floor_one):
index = 0
sum= 0
while(index < len(floor_one)):
sum += floor_one[index]
index += 1
return sum
def totol_chairs(floor_two):
index = 0
sum= 0
while(index < len(floor_two)):
sum += floor_two[index]
index += 1
return sum
def totol_chairs(floor_three):
index = 0
sum= 0
while(index < len(floor_three)):
sum += floor_three[index]
index += 1
return sum
def total_chairs(building):
allchairs = 0
index = 0
while(index<len(building)):
j = 0
while(j<len(building[index])):
allchairs = allchairs + building[index][j]
j = j + 1
index = index + 1
return allchairs
def max_floor(building):
max_floor = 0
index = 0
while(index<len(building)):
summation = 0
j = 0
while(j<len(building[index])):
summation = summation + building[index][j]
j = j + 1
if(summation>max_floor):
max_floor = index
index = index + 1
return max_floor
def find_max_class(building):
maximum = 0
index = 0
while(index < len(building)):
j = 0
while(j < len(building[index])):
if(building[index][j] > maximum):
maximum = building[index][j]
j = j + 1
index = index + 1
return maximum
setup()
lab 6 transpose
def setup():
row_11 = [20,15]
row_12 = [37,3]
matrix = [row_11,row_12]
transpose(matrix)
def transpose(matrix):
index=0
index2=0
while(index<len(matrix)):
print("|",end=" ")
while(index2<len(matrix[index])):
print(matrix[index2][index],end=" ")
index2 = index2 +1
index2 = 0
print("|")
index = index +1
setup()
row_11 = [20,15]
row_12 = [37,3]
matrix = [row_11,row_12]
transpose(matrix)
def transpose(matrix):
index=0
index2=0
while(index<len(matrix)):
print("|",end=" ")
while(index2<len(matrix[index])):
print(matrix[index2][index],end=" ")
index2 = index2 +1
index2 = 0
print("|")
index = index +1
setup()
lab 6 subtract
def setup():
row_11=[20,15]
row_12=[37,3]
matrix1=[row_11,row_12]
row_21=[4,16]
row_22=[51,34]
matrix2=[row_21,row_22]
new_matrix(matrix1,matrix2)
def new_matrix(matrix1,matrix2):
index =0
index2 =0
result=0
while(index<len(matrix1)):
print("|",end=" ")
while(index2<len(matrix1)):
result = matrix1[index][index2]-matrix2[index][index2]
print(result ,end=" ")
index2=index2+1
index2=0
print("|")
index=index+1
setup()
row_11=[20,15]
row_12=[37,3]
matrix1=[row_11,row_12]
row_21=[4,16]
row_22=[51,34]
matrix2=[row_21,row_22]
new_matrix(matrix1,matrix2)
def new_matrix(matrix1,matrix2):
index =0
index2 =0
result=0
while(index<len(matrix1)):
print("|",end=" ")
while(index2<len(matrix1)):
result = matrix1[index][index2]-matrix2[index][index2]
print(result ,end=" ")
index2=index2+1
index2=0
print("|")
index=index+1
setup()
lab 6 add matrix
def setup():
row_11=[20,15]
row_12=[37,3]
matrix1=[row_11,row_12]
row_21=[4,16]
row_22=[51,34]
matrix2=[row_21,row_22]
new_matrix(matrix1,matrix2)
def new_matrix(matrix1,matrix2):
index=0
index2=0
result=0
while(index<len(matrix1)):
print("|",end=" ")
while(index2<len(matrix1)):
result = matrix1[index][index2]+matrix2[index][index2]
print(result ,end=" ")
index2=index2+1
index2=0
print("|")
index=index+1
setup()
row_11=[20,15]
row_12=[37,3]
matrix1=[row_11,row_12]
row_21=[4,16]
row_22=[51,34]
matrix2=[row_21,row_22]
new_matrix(matrix1,matrix2)
def new_matrix(matrix1,matrix2):
index=0
index2=0
result=0
while(index<len(matrix1)):
print("|",end=" ")
while(index2<len(matrix1)):
result = matrix1[index][index2]+matrix2[index][index2]
print(result ,end=" ")
index2=index2+1
index2=0
print("|")
index=index+1
setup()
lab 6 display matrix
def setup():
row_11=[20,15]
row_12=[37,3]
matrix=[row_11,row_12]
show_matrix(matrix1)
def show_matrix(matrix):
index=0
index2=0
while(index<len(matrix)):
print("|",end=" ")
while(index2<len(matrix[index])):
print(matrix[index][index2],end=" ")
index2=index2+1
index2=0
print("|")
index=index+1
setup()
row_11=[20,15]
row_12=[37,3]
matrix=[row_11,row_12]
show_matrix(matrix1)
def show_matrix(matrix):
index=0
index2=0
while(index<len(matrix)):
print("|",end=" ")
while(index2<len(matrix[index])):
print(matrix[index][index2],end=" ")
index2=index2+1
index2=0
print("|")
index=index+1
setup()
วันเสาร์ที่ 24 ตุลาคม พ.ศ. 2558
lab 6 ILT
def setup():
print(' ######## ########## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ######## ## #######')
setup()
print(' ######## ########## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ## ## ##')
print(' ######## ## #######')
setup()
lab 6 display age
def setup():
age = [35,19,18,20,19,31]
print(age)
print('Display the age that less than 30 years old')
show_age(age)
def show_age(age):
count = 0
find_age = 30
while(count<len(age)):
if(age[count]<find_age):
print(age[count])
count = count + 1
setup()
age = [35,19,18,20,19,31]
print(age)
print('Display the age that less than 30 years old')
show_age(age)
def show_age(age):
count = 0
find_age = 30
while(count<len(age)):
if(age[count]<find_age):
print(age[count])
count = count + 1
setup()
lab 6 count age
def setup():
student_number = [1,2,3,4,5,6]
age = [35,19,18,20,19,31]
high = [177,182,170,169,185,160]
weight = [65,50,60,75,80,55]
data = [student_number,age,high,weight]
print(find_the_age(age),'students have age under 30 years old')
def find_the_age(age):
count = 0
count_age = 30
find_age = 0
while(count<len(age)):
if(age[count]<count_age):
find_age +=1
count = count + 1
return find_age
setup()
student_number = [1,2,3,4,5,6]
age = [35,19,18,20,19,31]
high = [177,182,170,169,185,160]
weight = [65,50,60,75,80,55]
data = [student_number,age,high,weight]
print(find_the_age(age),'students have age under 30 years old')
def find_the_age(age):
count = 0
count_age = 30
find_age = 0
while(count<len(age)):
if(age[count]<count_age):
find_age +=1
count = count + 1
return find_age
setup()
lab 6 find display and count bmi
def setup():
name = ["Keane","Giggs","Cole","Scholes","Park","Nani"]
student_number = [1,2,3,4,5,6]
age = [35,19,18,20,19,31]
high = [177,182,170,169,185,160]
weight = [95,50,90,75,60,48]
data = [student_number,age,high,weight,name]
find_bmi(student_number,name,weight,high)
print('There are',count_bmi(student_number,name,weight,high),'students that have BMI more than 25')
def find_bmi(student_number,name,weight,high):
index = 0
bmi = 0
count = 0
while(index<len(student_number)):
bmi = weight[count]/((high[count]/100)*2)
count = count + 1
print('BMI of ',name[index],bmi)
index = index + 1
def count_bmi(student_number,name,weight,high):
index = 0
bmi = 0
count = 0
while(index<len(student_number)):
bmi = weight[index]/((high[index]/100)*2)
if(bmi>25):
count += 1
index = index + 1
return count
setup()
name = ["Keane","Giggs","Cole","Scholes","Park","Nani"]
student_number = [1,2,3,4,5,6]
age = [35,19,18,20,19,31]
high = [177,182,170,169,185,160]
weight = [95,50,90,75,60,48]
data = [student_number,age,high,weight,name]
find_bmi(student_number,name,weight,high)
print('There are',count_bmi(student_number,name,weight,high),'students that have BMI more than 25')
def find_bmi(student_number,name,weight,high):
index = 0
bmi = 0
count = 0
while(index<len(student_number)):
bmi = weight[count]/((high[count]/100)*2)
count = count + 1
print('BMI of ',name[index],bmi)
index = index + 1
def count_bmi(student_number,name,weight,high):
index = 0
bmi = 0
count = 0
while(index<len(student_number)):
bmi = weight[index]/((high[index]/100)*2)
if(bmi>25):
count += 1
index = index + 1
return count
setup()
lab 6 display weight that less than 50 kg.
def setup():
weight = [95,50,90,75,60,48]
print('Display weight that under 50 kg.')
find_weight(weight)
def find_weight(weight):
count = 0
find_weight = 50
while(count<len(weight)):
if(weight[count]<find_weight):
print(weight[count])
count = count + 1
setup()
weight = [95,50,90,75,60,48]
print('Display weight that under 50 kg.')
find_weight(weight)
def find_weight(weight):
count = 0
find_weight = 50
while(count<len(weight)):
if(weight[count]<find_weight):
print(weight[count])
count = count + 1
setup()
lab 6 display number of student that have weight less than 50
def setup():
weight = [95,50,90,75,60,48]
print(find_weight(weight),'students have weight less than 50 kg.')
def find_weight(weight):
count = 0
find_weight = 50
count_weight = 0
while(count<len(weight)):
if(weight[count]<find_weight):
count_weight +=1
count = count + 1
return count_weight
setup()
weight = [95,50,90,75,60,48]
print(find_weight(weight),'students have weight less than 50 kg.')
def find_weight(weight):
count = 0
find_weight = 50
count_weight = 0
while(count<len(weight)):
if(weight[count]<find_weight):
count_weight +=1
count = count + 1
return count_weight
setup()
lab 6 student data Average age and minimum weight
def setup():
name = ["Keane","Giggs","Cole","Scholes","Park","Nani"]
student_number = [1,2,3,4,5,6]
age = [35,19,18,20,19,31]
high = [177,182,170,169,185,160]
weight = [95,50,90,75,60,48]
data = [student_number,age,high,weight,name]
print('Student name ',data[4][0])
print('Student number ',data[0][0])
print('Age ',data[1][0],'years old')
print('High ',data[2][0],'cm.')
print('Weight ',data[3][0],'kg.')
print('Student name ',data[4][1])
print('Student number ',data[0][1])
print('Age ',data[1][1],'years old')
print('High ',data[2][1],'cm.')
print('Weight ',data[3][1],'kg.')
print('Student name ',data[4][2])
print('Student number ',data[0][2])
print('Age ',data[1][2],'years old')
print('High ',data[2][2],'cm.')
print('Weight ',data[3][2],'kg.')
print('Student name ',data[4][3])
print('Student number ',data[0][3])
print('Age ',data[1][3],'years old')
print('High ',data[2][3],'cm.')
print('Weight ',data[3][3],'kg.')
print('Student name ',data[4][4])
print('Student number ',data[0][4])
print('Age ',data[1][4],'years old')
print('High ',data[2][4],'cm.')
print('Weight ',data[3][4],'kg.')
print('Student name ',data[4][5])
print('Student number ',data[0][5])
print('Age ',data[1][5],'years old')
print('High ',data[2][5],'cm.')
print('Weight ',data[3][5],'kg.')
print('Average age',(age[0]+age[1]+age[2]+age[3]+age[4]+age[5])/4,'Years old')
print('The minimum weight is',find_minimum_weight(weight),'kg.')
def find_minimum_weight(weight):
count = 0
minimum = 100
while(count < len(weight)):
if(weight[count] < minimum):
minimum = weight[count]
count = count + 1
return minimum
setup()
name = ["Keane","Giggs","Cole","Scholes","Park","Nani"]
student_number = [1,2,3,4,5,6]
age = [35,19,18,20,19,31]
high = [177,182,170,169,185,160]
weight = [95,50,90,75,60,48]
data = [student_number,age,high,weight,name]
print('Student name ',data[4][0])
print('Student number ',data[0][0])
print('Age ',data[1][0],'years old')
print('High ',data[2][0],'cm.')
print('Weight ',data[3][0],'kg.')
print('Student name ',data[4][1])
print('Student number ',data[0][1])
print('Age ',data[1][1],'years old')
print('High ',data[2][1],'cm.')
print('Weight ',data[3][1],'kg.')
print('Student name ',data[4][2])
print('Student number ',data[0][2])
print('Age ',data[1][2],'years old')
print('High ',data[2][2],'cm.')
print('Weight ',data[3][2],'kg.')
print('Student name ',data[4][3])
print('Student number ',data[0][3])
print('Age ',data[1][3],'years old')
print('High ',data[2][3],'cm.')
print('Weight ',data[3][3],'kg.')
print('Student name ',data[4][4])
print('Student number ',data[0][4])
print('Age ',data[1][4],'years old')
print('High ',data[2][4],'cm.')
print('Weight ',data[3][4],'kg.')
print('Student name ',data[4][5])
print('Student number ',data[0][5])
print('Age ',data[1][5],'years old')
print('High ',data[2][5],'cm.')
print('Weight ',data[3][5],'kg.')
print('Average age',(age[0]+age[1]+age[2]+age[3]+age[4]+age[5])/4,'Years old')
print('The minimum weight is',find_minimum_weight(weight),'kg.')
def find_minimum_weight(weight):
count = 0
minimum = 100
while(count < len(weight)):
if(weight[count] < minimum):
minimum = weight[count]
count = count + 1
return minimum
setup()
วันอาทิตย์ที่ 20 กันยายน พ.ศ. 2558
lab 4X summation
def setup():
number=20
count=1
summation=0
while count <= number:
summation = summation + count
count = count + 1
print(" The summation is",summation)
setup()
number=20
count=1
summation=0
while count <= number:
summation = summation + count
count = count + 1
print(" The summation is",summation)
setup()
lab 4X calculatoion of BMI
def setup():
weight = 50
high = 170
BMI = cal_BMI(high,weight)
print("BMI=",BMI)
def cal_BMI(high,weight):
print("Weight =",weight,"kg")
print("Height =",high,"cm")
highM = high/100
BMI = weight/(highM*highM)
return BMI
setup()
weight = 50
high = 170
BMI = cal_BMI(high,weight)
print("BMI=",BMI)
def cal_BMI(high,weight):
print("Weight =",weight,"kg")
print("Height =",high,"cm")
highM = high/100
BMI = weight/(highM*highM)
return BMI
setup()
lab 4X calculation of cricle
def setup():
radius = 50
print("Radius =",radius)
print("Diameter =",cal_dia(radius))
print("Area =",cal_area(radius))
print("Circumference =",cal_cir(radius))
def cal_cir(radius):
cir = 2*3.14*radius
return cir
def cal_area(radius):
area = 3.14*radius*radius
return area
def cal_dia(radius):
dia = radius*2
return dia
setup()
radius = 50
print("Radius =",radius)
print("Diameter =",cal_dia(radius))
print("Area =",cal_area(radius))
print("Circumference =",cal_cir(radius))
def cal_cir(radius):
cir = 2*3.14*radius
return cir
def cal_area(radius):
area = 3.14*radius*radius
return area
def cal_dia(radius):
dia = radius*2
return dia
setup()
lab 4X Grade
def setup():
score=78
print("Your score was =",score)
if score<101and score>=80:
print("you got A")
if score<80and score>=70:
print("you got B")
if score<70and score>=60:
print("you got C")
if score<60and score>=50:
print("you got D")
if score<50:
print("you got F")
setup()
score=78
print("Your score was =",score)
if score<101and score>=80:
print("you got A")
if score<80and score>=70:
print("you got B")
if score<70and score>=60:
print("you got C")
if score<60and score>=50:
print("you got D")
if score<50:
print("you got F")
setup()
lab 4X multiply table
def setup():
multiply = 24
count = 1
while (count<=12):
print(multiply,"*",count,"=",multiply*count)
count = count + 1
setup()
multiply = 24
count = 1
while (count<=12):
print(multiply,"*",count,"=",multiply*count)
count = count + 1
setup()
วันอาทิตย์ที่ 13 กันยายน พ.ศ. 2558
lab 4 loan payment
void setup() {
size(500, 600);
background(126, 36, 12);
textAlign(LEFT);
textSize(20);
fill(0, 255, 0);
text("Monthly Loan Payment", 170, 30);
textSize(13);
fill(0, 0, 255);
float loanAmount = 5000;
float loanTerm = 1;
float interestRate = 12;
loanPayment(loanAmount, loanTerm, interestRate);
}
void loanPayment(float loanAmount, float loanTerm, float rate) {
loanTerm = loanTerm*12;
float percen = ((rate/100)/loanTerm);
float B = percen/(1-(pow(1+percen, -loanTerm)));
float paymentAmount = loanAmount*B;
float payment12month = paymentAmount*loanTerm;
text("Loan Amount : $"+loanAmount, 10, 65);
text("Loan Term : "+(int)(loanTerm)+" months", 10, 90);
text("Interset Rate : "+nf(rate, 0, 2)+" %", 10, 115);
text("Payment Every Month : $"+nf(paymentAmount, 0, 2), 275, 65);
text("Total of 12 Payments : $"+nf(payment12month, 0, 2), 275, 90);
text("Total Interset : $"+nf((payment12month-loanAmount), 0, 2), 275, 115);
int count = 1;
float interest = loanAmount*((rate/100)/loanTerm);
float principal = paymentAmount - interest;
float endBal = loanAmount - principal;
float totalInterest = interest;
float begin;
int y = 25;
text("Payment No.", 20, 155);
text("Interest", 120, 155);
text("Princical", 200, 155);
text("Unpaid Balance", 280, 155);
text("Total interest", 400, 155);
while (count <= loanTerm) {
text(nf(count, 2), 50, 155+y);
text("$"+nf(interest, 0, 2), 120, 155+y);
text("$"+nf(principal, 0, 2), 200, 155+y);
text("$"+nf(endBal, 0, 2), 300, 155+y);
text("$"+nf(totalInterest, 0, 2), 420, 155+y);
begin = endBal;
interest = begin*((rate/100)/loanTerm);
principal = paymentAmount - interest;
endBal = abs(begin - principal);
totalInterest = totalInterest + interest;
count = count +1;
y = y + 30;
}
}
size(500, 600);
background(126, 36, 12);
textAlign(LEFT);
textSize(20);
fill(0, 255, 0);
text("Monthly Loan Payment", 170, 30);
textSize(13);
fill(0, 0, 255);
float loanAmount = 5000;
float loanTerm = 1;
float interestRate = 12;
loanPayment(loanAmount, loanTerm, interestRate);
}
void loanPayment(float loanAmount, float loanTerm, float rate) {
loanTerm = loanTerm*12;
float percen = ((rate/100)/loanTerm);
float B = percen/(1-(pow(1+percen, -loanTerm)));
float paymentAmount = loanAmount*B;
float payment12month = paymentAmount*loanTerm;
text("Loan Amount : $"+loanAmount, 10, 65);
text("Loan Term : "+(int)(loanTerm)+" months", 10, 90);
text("Interset Rate : "+nf(rate, 0, 2)+" %", 10, 115);
text("Payment Every Month : $"+nf(paymentAmount, 0, 2), 275, 65);
text("Total of 12 Payments : $"+nf(payment12month, 0, 2), 275, 90);
text("Total Interset : $"+nf((payment12month-loanAmount), 0, 2), 275, 115);
int count = 1;
float interest = loanAmount*((rate/100)/loanTerm);
float principal = paymentAmount - interest;
float endBal = loanAmount - principal;
float totalInterest = interest;
float begin;
int y = 25;
text("Payment No.", 20, 155);
text("Interest", 120, 155);
text("Princical", 200, 155);
text("Unpaid Balance", 280, 155);
text("Total interest", 400, 155);
while (count <= loanTerm) {
text(nf(count, 2), 50, 155+y);
text("$"+nf(interest, 0, 2), 120, 155+y);
text("$"+nf(principal, 0, 2), 200, 155+y);
text("$"+nf(endBal, 0, 2), 300, 155+y);
text("$"+nf(totalInterest, 0, 2), 420, 155+y);
begin = endBal;
interest = begin*((rate/100)/loanTerm);
principal = paymentAmount - interest;
endBal = abs(begin - principal);
totalInterest = totalInterest + interest;
count = count +1;
y = y + 30;
}
}
lab 4 movies
int eye_size = 50;
int red = 255;
int green = 255;
int blue = 0;
void setup () {
size(700, 500);
background(0, 0, 0);
strokeWeight(3);
}
void draw() {
fill(red, green, blue);
rect(40, 50, 300, 400);
rect(360, 50, 300, 400);
eye(70, 100, eye_size);
eye(400, 100, eye_size);
mouth(90, 300);
}
void mouseMoved() {
red = red -5;
green = green - 15;
blue = blue - 51;
if (red==0) {
red = 255;
}
if (green==0) {
green = 255;
}
if (blue==0) {
blue = 255;
}
}
void eye(int eyeposX, int eyeposY, int eye_size) {
int picture =0;
int new_picture = 0;
int number = 2;
while (picture<number) {
fill(255, 255, 255);
ellipse(eyeposX+50+new_picture, eyeposY+50, eye_size+70, eye_size+70);
fill(red, green, blue);
ellipse(eyeposX+50+new_picture, eyeposY+50, eye_size+20, eye_size+20);
fill(0, 0, 0);
ellipse(eyeposX+50+new_picture, eyeposY+50, eye_size/2, eye_size/2);
new_picture = new_picture + 120;
picture = picture +1;
}
}
void mouth(int mouthposX, int mouthposY) {
int picture =0;
int new_picture = 0;
int number = 2;
while (picture<number) {
fill(210, 54, 27);
ellipse(mouthposX+100+new_picture, mouthposY+30, 280, 60);
line(mouthposX-30+new_picture, mouthposY+30, mouthposX+220+new_picture, mouthposY+30);
new_picture = new_picture +320 ;
picture = picture +1;
}
}
int red = 255;
int green = 255;
int blue = 0;
void setup () {
size(700, 500);
background(0, 0, 0);
strokeWeight(3);
}
void draw() {
fill(red, green, blue);
rect(40, 50, 300, 400);
rect(360, 50, 300, 400);
eye(70, 100, eye_size);
eye(400, 100, eye_size);
mouth(90, 300);
}
void mouseMoved() {
red = red -5;
green = green - 15;
blue = blue - 51;
if (red==0) {
red = 255;
}
if (green==0) {
green = 255;
}
if (blue==0) {
blue = 255;
}
}
void eye(int eyeposX, int eyeposY, int eye_size) {
int picture =0;
int new_picture = 0;
int number = 2;
while (picture<number) {
fill(255, 255, 255);
ellipse(eyeposX+50+new_picture, eyeposY+50, eye_size+70, eye_size+70);
fill(red, green, blue);
ellipse(eyeposX+50+new_picture, eyeposY+50, eye_size+20, eye_size+20);
fill(0, 0, 0);
ellipse(eyeposX+50+new_picture, eyeposY+50, eye_size/2, eye_size/2);
new_picture = new_picture + 120;
picture = picture +1;
}
}
void mouth(int mouthposX, int mouthposY) {
int picture =0;
int new_picture = 0;
int number = 2;
while (picture<number) {
fill(210, 54, 27);
ellipse(mouthposX+100+new_picture, mouthposY+30, 280, 60);
line(mouthposX-30+new_picture, mouthposY+30, mouthposX+220+new_picture, mouthposY+30);
new_picture = new_picture +320 ;
picture = picture +1;
}
}
lab 4 flock of birds
int space = 5;
void setup() {
size(900, 500);
strokeWeight(6);
}
void draw() {
background(34, 88, 126);
int posX = mouseX;
int posY = mouseY;
if (frameCount%30>15) {
space = 120;
} else {
space = -55;
}
draw_birds( posX, posY);
}
void draw_birds(int posX, int posY) {
int radius = 60;
int string_length = 50;
int birds = 0;
int new_birds = 0;
int new_birds2=0;
int number = 6;
while (birds<number) {
fill(255, 0, 0);
stroke(0, 0, 0);
ellipse(posX+new_birds, posY+new_birds2, radius, radius);
fill(255, 255, 255);
stroke(0, 0, 0);
line(posX+30+new_birds, posY+new_birds2, posX+70+new_birds, posY+new_birds2+string_length-space);
line(posX-30+new_birds, posY+new_birds2, posX-70+new_birds, posY+new_birds2+string_length-space);
noStroke();
ellipse(posX+new_birds-13, posY+new_birds2-10, radius-45, radius-45);
ellipse(posX+new_birds+13, posY+new_birds2-10, radius-45, radius-45);
fill(0, 0, 0);
ellipse(posX+new_birds-13, posY+new_birds2-7, radius-55, radius-55);
ellipse(posX+new_birds+13, posY+new_birds2-7, radius-55, radius-55);
fill(253, 249, 64);
triangle(posX+new_birds-30, posY+new_birds2+40, posX+new_birds-10, posY+new_birds2+5, posX+new_birds+10, posY+new_birds2+5);
new_birds = new_birds +150;
new_birds2 = new_birds2+50;
birds = birds +1;
}
}
void setup() {
size(900, 500);
strokeWeight(6);
}
void draw() {
background(34, 88, 126);
int posX = mouseX;
int posY = mouseY;
if (frameCount%30>15) {
space = 120;
} else {
space = -55;
}
draw_birds( posX, posY);
}
void draw_birds(int posX, int posY) {
int radius = 60;
int string_length = 50;
int birds = 0;
int new_birds = 0;
int new_birds2=0;
int number = 6;
while (birds<number) {
fill(255, 0, 0);
stroke(0, 0, 0);
ellipse(posX+new_birds, posY+new_birds2, radius, radius);
fill(255, 255, 255);
stroke(0, 0, 0);
line(posX+30+new_birds, posY+new_birds2, posX+70+new_birds, posY+new_birds2+string_length-space);
line(posX-30+new_birds, posY+new_birds2, posX-70+new_birds, posY+new_birds2+string_length-space);
noStroke();
ellipse(posX+new_birds-13, posY+new_birds2-10, radius-45, radius-45);
ellipse(posX+new_birds+13, posY+new_birds2-10, radius-45, radius-45);
fill(0, 0, 0);
ellipse(posX+new_birds-13, posY+new_birds2-7, radius-55, radius-55);
ellipse(posX+new_birds+13, posY+new_birds2-7, radius-55, radius-55);
fill(253, 249, 64);
triangle(posX+new_birds-30, posY+new_birds2+40, posX+new_birds-10, posY+new_birds2+5, posX+new_birds+10, posY+new_birds2+5);
new_birds = new_birds +150;
new_birds2 = new_birds2+50;
birds = birds +1;
}
}
lab 4 multiply table
void setup() {
int multiply = 24;
int count = 1;
while (count<=12) {
println(multiply+"*"+count+"="+multiply*count);
count = count + 1;
}
}
int multiply = 24;
int count = 1;
while (count<=12) {
println(multiply+"*"+count+"="+multiply*count);
count = count + 1;
}
}
lab 4 summation of prime number
void setup() {
int number=30;
int divide=2;
int count=2;
int sum=0;
boolean primeNum = true;
while (count<=number) {
while (divide<count) {
if (count%divide==0) {
primeNum=false;
break;
} else primeNum=true;
divide= divide+ 1;
}
if (primeNum) {
print(count+" ");
sum=sum+count;
}
divide=2;
count= count +1;
}
println(" ");
println("Sum = "+sum);
}
int number=30;
int divide=2;
int count=2;
int sum=0;
boolean primeNum = true;
while (count<=number) {
while (divide<count) {
if (count%divide==0) {
primeNum=false;
break;
} else primeNum=true;
divide= divide+ 1;
}
if (primeNum) {
print(count+" ");
sum=sum+count;
}
divide=2;
count= count +1;
}
println(" ");
println("Sum = "+sum);
}
lab 4 summation
void setup() {
int count = 1;
int sum = 0;
int number = 15;
while (count <= number) {
sum = sum + count;
print(count);
print(" + ");
count = count+1;
}
print(" = "+sum);
}
int count = 1;
int sum = 0;
int number = 15;
while (count <= number) {
sum = sum + count;
print(count);
print(" + ");
count = count+1;
}
print(" = "+sum);
}
lab 4 balloons
void setup() {
size(600, 600);
}
void draw() {
background(160, 231, 231);
int X = mouseX;
int Y = mouseY;
if (Y<50) {
Y = 50;
fill(225, 0, 0);
}
if (Y>500) {
Y = 500;
fill(0, 225, 0);
}
draw_balloon(X, Y);
}
void draw_balloon(int X, int Y) {
int radius = 50;
int string_length = 80;
int number = 10;
int balloon = 0;
int new_balloon = 0;
while (balloon<number) {
line(X+new_balloon, Y, X+new_balloon, Y + string_length);
ellipse(X+new_balloon, Y, radius, radius);
new_balloon=new_balloon+60;
balloon=balloon+1;
}
}
size(600, 600);
}
void draw() {
background(160, 231, 231);
int X = mouseX;
int Y = mouseY;
if (Y<50) {
Y = 50;
fill(225, 0, 0);
}
if (Y>500) {
Y = 500;
fill(0, 225, 0);
}
draw_balloon(X, Y);
}
void draw_balloon(int X, int Y) {
int radius = 50;
int string_length = 80;
int number = 10;
int balloon = 0;
int new_balloon = 0;
while (balloon<number) {
line(X+new_balloon, Y, X+new_balloon, Y + string_length);
ellipse(X+new_balloon, Y, radius, radius);
new_balloon=new_balloon+60;
balloon=balloon+1;
}
}
วันอาทิตย์ที่ 6 กันยายน พ.ศ. 2558
Lab 3 leap_year
String leap_year;
void setup() {
size(500, 500);
}
void draw() {
int year = 1996;
background(255,255,255);
fill(255,0,0);
textSize(50);
textAlign(CENTER);
text("Year is "+year, width/2, 200);
text(year+" is "+leap_year, width/2, 250);
if (year%4==0&&year%100!=0)
leap_year="Leap Year";
else if (year%4==0&&year%100==0)
if (year%400==0)
leap_year="Leap Year";
else if (year%400!=0)
leap_year="not Leap Year";
else leap_year="not Leap Year";
}
void setup() {
size(500, 500);
}
void draw() {
int year = 1996;
background(255,255,255);
fill(255,0,0);
textSize(50);
textAlign(CENTER);
text("Year is "+year, width/2, 200);
text(year+" is "+leap_year, width/2, 250);
if (year%4==0&&year%100!=0)
leap_year="Leap Year";
else if (year%4==0&&year%100==0)
if (year%400==0)
leap_year="Leap Year";
else if (year%400!=0)
leap_year="not Leap Year";
else leap_year="not Leap Year";
}
Lab 3 battery
int space = 5;
int space2 = 5;
int posY=2;
void setup() {
size(500, 500);
}
void draw() {
background(0, 0, 0);
fill(225, 225, 225);
strokeWeight(5);
stroke(255, 255, 255);
rect(150, 80, 200, 380);
rect(190, 20, 40, 60);
rect(270, 20, 40, 60);
fill(0, 255, 0);
rect(152, 85, 195, 370);
fill(0, 0, 0);
rect(152, 85, 195, 4+space);
space = (space + 1 )%width;
if ( space>=368) {
space = (space - 1)%width;
fill(0, 225, 0);
stroke(255, 255, 255);
rect(152, 455-posY, 195, 2+space2);
if (space2<370) {
space2=(space2 +1)%width;
posY=(posY+1)%width;
}
}
}
int space2 = 5;
int posY=2;
void setup() {
size(500, 500);
}
void draw() {
background(0, 0, 0);
fill(225, 225, 225);
strokeWeight(5);
stroke(255, 255, 255);
rect(150, 80, 200, 380);
rect(190, 20, 40, 60);
rect(270, 20, 40, 60);
fill(0, 255, 0);
rect(152, 85, 195, 370);
fill(0, 0, 0);
rect(152, 85, 195, 4+space);
space = (space + 1 )%width;
if ( space>=368) {
space = (space - 1)%width;
fill(0, 225, 0);
stroke(255, 255, 255);
rect(152, 455-posY, 195, 2+space2);
if (space2<370) {
space2=(space2 +1)%width;
posY=(posY+1)%width;
}
}
}
Lab 3 grade
void setup() {
size(500, 500);
}
void draw() {
background(0, 255, 0);
int score=78;
String grade;
fill(0);
textSize(50);
text("Score="+score, 130, 100);
if (score<101&&score>79) {
grade="A";
} else if (score<=79&&score>69) {
grade="B";
} else if (score<=69&&score>59) {
grade="C";
} else if (score<=59&&score>49) {
grade="D";
} else if (score<=49&&score>=0) {
grade = "F";
} else {
grade = "Error";
}
fill(255, 0, 0);
textSize(65);
text("Grade="+grade, 120, 250);
}
size(500, 500);
}
void draw() {
background(0, 255, 0);
int score=78;
String grade;
fill(0);
textSize(50);
text("Score="+score, 130, 100);
if (score<101&&score>79) {
grade="A";
} else if (score<=79&&score>69) {
grade="B";
} else if (score<=69&&score>59) {
grade="C";
} else if (score<=59&&score>49) {
grade="D";
} else if (score<=49&&score>=0) {
grade = "F";
} else {
grade = "Error";
}
fill(255, 0, 0);
textSize(65);
text("Grade="+grade, 120, 250);
}
Lab 3 music(move)
void setup () {
size(500, 500);
}
void draw() {
background(0, 255, 255);
draw_music(mouseX, mouseY);
}
void draw_music(int X, int Y) {
fill(44, 235, 16);
stroke(255, 255, 255);
rect(X, Y, 450, 450);//Green
stroke(255, 255, 255);
fill(255, 255, 255);
ellipse(X+230, Y+200, 360, 300);//circle
stroke(255, 255, 255);
triangle(X+165, Y+405, X+315, Y+315, X+175, Y+225);//triangle
fill(0, 0, 0);
textSize(18);
text("shu thag line - timethai Feat.kratae R siam ", X+35, Y+425);
fill(0, 255, 0);
textSize(145);
text("LINE ", X+80, Y+250);
}
size(500, 500);
}
void draw() {
background(0, 255, 255);
draw_music(mouseX, mouseY);
}
void draw_music(int X, int Y) {
fill(44, 235, 16);
stroke(255, 255, 255);
rect(X, Y, 450, 450);//Green
stroke(255, 255, 255);
fill(255, 255, 255);
ellipse(X+230, Y+200, 360, 300);//circle
stroke(255, 255, 255);
triangle(X+165, Y+405, X+315, Y+315, X+175, Y+225);//triangle
fill(0, 0, 0);
textSize(18);
text("shu thag line - timethai Feat.kratae R siam ", X+35, Y+425);
fill(0, 255, 0);
textSize(145);
text("LINE ", X+80, Y+250);
}
Lab 3 flying_bird
int wing;
void setup() {
size(500, 500);
strokeWeight(6);
}
void draw() {
background(48, 231, 231);
wing=mouseY;
if (frameCount%60>30) {
wing+=130;
} else {
wing-=130;
}
draw_flybird(mouseX, mouseY);
}
void draw_flybird(int x, int y) {
fill(225, 0, 0);
stroke(0, 0, 0);
ellipse(x, y, 90, 90);
line(x+45, y, x+130, wing);
line(x-45, y, x-130, wing);
line(x+50, y, x+135, wing);
line(x-50, y, x-135, wing);
line(x+55, y, x+140, wing);
line(x-55, y, x-140, wing);
line(x+60, y, x+145, wing);
line(x-60, y, x-145, wing);
fill(253, 249, 64);
noStroke();
triangle(x+10, y+10, x-10, y+30, x-30, y+10);
noStroke();
fill(255, 255, 255);
ellipse(x-25, y-5, 25, 20);
ellipse(x+25, y-5, 25, 20);
fill(0, 0, 0);
ellipse(x-25, y-5, 10, 10);
ellipse(x+25, y-5, 10, 10);
}
void setup() {
size(500, 500);
strokeWeight(6);
}
void draw() {
background(48, 231, 231);
wing=mouseY;
if (frameCount%60>30) {
wing+=130;
} else {
wing-=130;
}
draw_flybird(mouseX, mouseY);
}
void draw_flybird(int x, int y) {
fill(225, 0, 0);
stroke(0, 0, 0);
ellipse(x, y, 90, 90);
line(x+45, y, x+130, wing);
line(x-45, y, x-130, wing);
line(x+50, y, x+135, wing);
line(x-50, y, x-135, wing);
line(x+55, y, x+140, wing);
line(x-55, y, x-140, wing);
line(x+60, y, x+145, wing);
line(x-60, y, x-145, wing);
fill(253, 249, 64);
noStroke();
triangle(x+10, y+10, x-10, y+30, x-30, y+10);
noStroke();
fill(255, 255, 255);
ellipse(x-25, y-5, 25, 20);
ellipse(x+25, y-5, 25, 20);
fill(0, 0, 0);
ellipse(x-25, y-5, 10, 10);
ellipse(x+25, y-5, 10, 10);
}
Lab 3 movies(change color)
int eye_size = 100;
int red = 255;
int green = 255;
int blue = 0;
void setup () {
size(500, 500);
background(34, 23, 44);
strokeWeight(3);
}
void draw() {
fill(red, green, blue);
rect(50, 50, 400, 400);
eye(100, 150, eye_size);
eye(300, 150, eye_size);
mouth(150, 300);
}
void mouseMoved() {
red = red -5;
green = green - 15;
blue = blue - 51;
if (red==0) {
red = 255;
}
if (green==0) {
green = 255;
}
if (blue==0) {
blue = 255;
}
}
void eye(int eyeposX, int eyeposY, int eye_size) {
fill(255, 255, 255);
ellipse(eyeposX+50, eyeposY+50, eye_size+70, eye_size+60);
fill(red, green, blue);
ellipse(eyeposX+50, eyeposY+50, eye_size, eye_size);
fill(0, 0, 0);
ellipse(eyeposX+50, eyeposY+50, eye_size/2, eye_size/2);
line(eyeposX+90, eyeposY+20, eyeposX+130, eyeposY-40);
line(eyeposX+50, eyeposY-60, eyeposX+50, eyeposY);
line(eyeposX+10, eyeposY+20, eyeposX-30, eyeposY-40);
}
void mouth(int mouthposX, int mouthposY) {
fill(210, 54, 27);
ellipse(mouthposX+100, mouthposY+60, 350, 80);
line(mouthposX-30, mouthposY+60, mouthposX+240, mouthposY+60);
}
int red = 255;
int green = 255;
int blue = 0;
void setup () {
size(500, 500);
background(34, 23, 44);
strokeWeight(3);
}
void draw() {
fill(red, green, blue);
rect(50, 50, 400, 400);
eye(100, 150, eye_size);
eye(300, 150, eye_size);
mouth(150, 300);
}
void mouseMoved() {
red = red -5;
green = green - 15;
blue = blue - 51;
if (red==0) {
red = 255;
}
if (green==0) {
green = 255;
}
if (blue==0) {
blue = 255;
}
}
void eye(int eyeposX, int eyeposY, int eye_size) {
fill(255, 255, 255);
ellipse(eyeposX+50, eyeposY+50, eye_size+70, eye_size+60);
fill(red, green, blue);
ellipse(eyeposX+50, eyeposY+50, eye_size, eye_size);
fill(0, 0, 0);
ellipse(eyeposX+50, eyeposY+50, eye_size/2, eye_size/2);
line(eyeposX+90, eyeposY+20, eyeposX+130, eyeposY-40);
line(eyeposX+50, eyeposY-60, eyeposX+50, eyeposY);
line(eyeposX+10, eyeposY+20, eyeposX-30, eyeposY-40);
}
void mouth(int mouthposX, int mouthposY) {
fill(210, 54, 27);
ellipse(mouthposX+100, mouthposY+60, 350, 80);
line(mouthposX-30, mouthposY+60, mouthposX+240, mouthposY+60);
}
วันจันทร์ที่ 31 สิงหาคม พ.ศ. 2558
Balloon
void setup(){
size(500,500);
}
void draw(){
background(160,231,231);
int X = 250;
int Y = mouseY;
if(Y<50){
Y = 50;
fill(225,0,0);
}else{
fill(0,225,0);
}
draw_balloon(X,Y);
}
void draw_balloon(int X, int Y){
int radius = 100;
int string_length = 150;
line(X, Y, X, Y + string_length);
ellipse(X, Y, radius, radius);
}
size(500,500);
}
void draw(){
background(160,231,231);
int X = 250;
int Y = mouseY;
if(Y<50){
Y = 50;
fill(225,0,0);
}else{
fill(0,225,0);
}
draw_balloon(X,Y);
}
void draw_balloon(int X, int Y){
int radius = 100;
int string_length = 150;
line(X, Y, X, Y + string_length);
ellipse(X, Y, radius, radius);
}
วันอาทิตย์ที่ 30 สิงหาคม พ.ศ. 2558
Lab 1 possitive (resize)
int resizing = 50;
void setup(){
size(500,500);
//frameRate(3);
}
void draw() {
background(128,0,128);
fill(255,255,255);
noStroke();
rect(160,290,300-resizing,100-resizing);
rect(260,200, 100- resizing,300- resizing);
resizing = ( resizing + 1)%width;
}
void setup(){
size(500,500);
//frameRate(3);
}
void draw() {
background(128,0,128);
fill(255,255,255);
noStroke();
rect(160,290,300-resizing,100-resizing);
rect(260,200, 100- resizing,300- resizing);
resizing = ( resizing + 1)%width;
}
ปัญหา error
สาเหตุ : ในการประกาศชื่อตัวแปรห้ามเว้นตัวอักษร
วิธีการแก้ไข : 1. พิมพ์ชื่อตัวแปรให้ติดกัน
2. ใช้ underscore ( _ ) แทนการเว้นวรรคของคำนั้นๆ
Lab 2 Calculation of BMI
void setup(){
float weight = 50;
float heightCentimeter = 169;
float bmi = cal_bmi(weight,heightCentimeter);
println("bmi="+bmi);
println("weight="+weight);
println("height="+heightCentimeter);
}
float cal_bmi(float weight, float heightCentimeter)
{
float heightMeter; //ความสูง(เมตร)
float bmi; //ค่าดัชนีมวล
heightMeter = heightCentimeter/100;
bmi = weight/(heightMeter*heightMeter);
return bmi;
}
float weight = 50;
float heightCentimeter = 169;
float bmi = cal_bmi(weight,heightCentimeter);
println("bmi="+bmi);
println("weight="+weight);
println("height="+heightCentimeter);
}
float cal_bmi(float weight, float heightCentimeter)
{
float heightMeter; //ความสูง(เมตร)
float bmi; //ค่าดัชนีมวล
heightMeter = heightCentimeter/100;
bmi = weight/(heightMeter*heightMeter);
return bmi;
}
Lab 2 Calculation of Cricle
void setup()
{
float area = calculation_area(15); // เส้นรอบวง
float circumference = calculation_circumference(15); // พื้นที่
float diameter = calculation_diameter(15); // เส้นผ่านศูนย์กลาง
println("area="+area);
println("circumference="+circumference);
println("diameter="+diameter);
}
float calculation_area(float raidus){
float area;
area = PI*(raidus*raidus);
return area;
}
float calculation_circumference(float raidus){
float circumference;
circumference = 2*PI*raidus;
return circumference;
}
float calculation_diameter(float raidus){
float diameter;
diameter = 2*raidus;
return diameter;
}
{
float area = calculation_area(15); // เส้นรอบวง
float circumference = calculation_circumference(15); // พื้นที่
float diameter = calculation_diameter(15); // เส้นผ่านศูนย์กลาง
println("area="+area);
println("circumference="+circumference);
println("diameter="+diameter);
}
float calculation_area(float raidus){
float area;
area = PI*(raidus*raidus);
return area;
}
float calculation_circumference(float raidus){
float circumference;
circumference = 2*PI*raidus;
return circumference;
}
float calculation_diameter(float raidus){
float diameter;
diameter = 2*raidus;
return diameter;
}
สมัครสมาชิก:
ความคิดเห็น (Atom)
