def setup():
a = [student( "Oat" ,1,18,52,165),
student("Nice",2,19,50,170),
student("Loemax",3,21,65,170),
student("Shin",4,20,63,168)]
sort_by_age(a)
def sort_by_age(a):
i = 0
while(i<len(a)):
j = 0
while(j<len(a)):
if(a[j].get_age!=len(a)-1 and a[j].get_age()>a[i].get_age()):
backup = a[i]
a[i] = a[j]
a[j] = backup
j = j+1
i = i+1
i = 0
while(i<len(a)):
a[i].display()
i = i+1
class 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("Name : ",self.name)
print("Student ID : ",self.id)
print("Age : ",self.age)
print("Weight : ",self.weight)
print("Height : ",self.height)
print("")
def get_age(self):
return self.age
setup()
ไม่มีความคิดเห็น:
แสดงความคิดเห็น