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

Lab 7 - (Class) Find/count number of students with age < 30

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_age(self):
        return self.age
   
def setup():
    info = [student("Buntun",18,50,160),
            student("FlukeKnub",19,75,199),
            student("PeeJa",32,60,150),
            student("Nutdech",18,58,185),
            student("BasBomba",20,60,180)]
    find_age(info)
       
def find_age(info):
    i = 0
    count = 0
    while (i<len(info)):
        age = info[i].get_age()
        if (age < 30):
           info[i].display()
           count = count+1
        i = i+1
    print()
    print ("Number member has age less than 30 =",count)
   
setup()

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

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