A = data_student("A",100,10,80,160)
B = data_student("B",101,5,56,162)
C = data_student("C",102,15,96,182)
D = data_student("D",103,4,70,160)
data = [A,B,C,D]
print("Everage age is ",find_everage_age(data))
print("Have student age low 30 about",count_age_low30(data))
sort_by_age(data)
display_array(data)
def display_array(data):
count = 0
while(count<len(data)):
data[count].display()
count += 1
def sort_by_age(data):
count = 1
while(check(data)):
if(data[count].replay_age()<data[count-1].replay_age()):
backup_id = data[count].replay_id()
backup_name = data[count].replay_name()
backup_age = data[count].replay_age()
backup_weight = data[count].replay_weight()
backup_height = data[count].replay_height()
data[count].get_id(data[count-1].replay_id())
data[count].get_name(data[count-1].replay_name())
data[count].get_age(data[count-1].replay_age())
data[count].get_weight(data[count-1].replay_weight())
data[count].get_height(data[count-1].replay_height())
data[count-1].get_id(backup_id)
data[count-1].get_name(backup_name)
data[count-1].get_age(backup_age)
data[count-1].get_height(backup_weight)
data[count-1].get_weight(backup_height)
count += 1
if(count == len(data)):
count = 1
def check(data):
count=0
while(count<len(data)-1):
if(data[count].replay_age()>data[count+1].replay_age()):
return True
count += 1
return False
def count_age_low30(data):
result = 0
count = 0
while(count<len(data)):
if(find_age_low30(data[count].replay_age())):
result +=1
count += 1
return result
def find_age_low30(data):
if(data<30):
return True
else:
return False
def find_everage_age(data):
result = 0
count = 0
while(count<len(data)):
result = result + data[count].replay_age()
count += 1
result = result / len(data)
return result
class data_student():
def __init__(self,name,iD,age,weight,height):
self.name = name
self.iD = iD
self.age = age
self.weight = weight
self.height = height
def display(self):
print(".......................")
print("ID IS ",self.iD)
print("name ",self.name)
print("age ",self.age)
print("weight",self.weight)
print("height",self.height)
def replay_age(self):
return self.age
def replay_id(self):
return self.iD
def replay_name(self):
return self.name
def replay_weight(self):
return self.weight
def replay_height(self):
return self.height
def get_id(self,iD):
self.iD = iD
def get_name(self,name):
self.name = name
def get_age(self,age):
self.age = age
def get_weight(self,weight):
self.weight = weight
def get_height(self,height):
self.height = height
setup()
Everage age is 8.5 Have student age low 30 about 4 ....................... ID IS 103 name D age 4 weight 70 height 160 ....................... ID IS 101 name B age 5 weight 56 height 162 ....................... ID IS 100 name A age 10 weight 80 height 160 ....................... ID IS 102 name C age 15 weight 96 height 182
ไม่มีความคิดเห็น:
แสดงความคิดเห็น