วันเสาร์ที่ 31 ตุลาคม พ.ศ. 2558

Lab 7 - (Class) Find minimum weight of students

class student:

    def __init__(self,name,age,weight,height):
        self.name = name
        self.age = age
        self.weight = weight
        self.height = height

    def display(self):
        print(self.name, end = "   ")
        print(self.age, end = "   ")
        print(self.weight, end = "   ")
        print(self.height, end = "   ")
        print()
         
    def get_weight(self):
        return self.weight
   
def setup():
    info = [student("Buntun",18,54,160),
            student("FlukeKnub",19,75,199),
            student("PeeJa",32,60,150),
            student("Nutdech",18,51,185),
            student("BasBomba",20,65,180)]
    find_weight(info)
       
def find_weight(info):
    min = 0
    i = 1
    count = 0
    while (i<len(info)):
        weight_min = info[min].get_weight()
        weight = info[i].get_weight()
        if (weight_min > weight):
           weight_min = weight
           count = i
        i = i+1
    info[count].display()
   
setup()

ไม่มีความคิดเห็น:

แสดงความคิดเห็น