วันอาทิตย์ที่ 1 พฤศจิกายน พ.ศ. 2558

Lab 7 - Student (Weight)

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("ID :",self.ID)
        print("Age :",self.age)
        print("Weight :",self.weight)
        print("Height :",self.height)

    def get_weight(self):
        return self.weight

def setup():
    std = [Student("ant",58001,39,55,165),
           Student("bird",58010,25,75,170),
           Student("cat",58011,19,44,155),
           Student("dog",58100,30,72,169),
           Student("eagle",58101,22,70,178),
           Student("frog",58110,18,100,175)]

    print("Number of students with weight < 50 =",find_numWeight_lessthan50(std),"\n")
    i = 0
    while(i < len(std)):
        if(std[i].get_weight() < 50):
            std[i].display()
        i += 1


def find_numWeight_lessthan50(student):
    i = 0
    count = 0
    while(i < len(student)):
        if(student[i].get_weight() < 50):
            count += 1
        i += 1
    return count

setup()

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

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