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

Lab 7 - (Class) Display student records with weight < 50

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,43,160),
            student("FlukeKnub",19,75,199),
            student("PeeJa",32,60,150),
            student("Nutdech",18,58,185),
            student("BasBomba",20,60,180)]
    find_weight(info)
       
def find_weight(info):
    i = 0
    count = 0
    while (i<len(info)):
        weight = info[i].get_weight()
        if (weight < 50):
           info[i].display()
        i = i+1
    print()
   
setup()

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

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