วันศุกร์ที่ 23 ตุลาคม พ.ศ. 2558

Lab 6 - Student Data (Age)

def setup():
    student_name = ["ant","bird","cat","dog","eagle","frog"]
    student_id = [58001,58010,58011,58100,58101,58110]
    student_age = [39,25,19,30,22,18]
    student_weight = [55,75,44,72,70,100]
    student_height = [165,170,155,169,178,175]
   
    display(student_name,student_id,student_age,student_weight,student_height)
   
 
def display(name,ID,age,weight,height):
    print("Number of students with age < 30 =",find_numAge_lessthan30(age))
    i = 0
    insertionSort_byAge(name,ID,age,weight,height)
    while(i < len(name)):
        print("\nName :",name[i])
        print("ID :",ID[i])
        print("Age :",age[i])
        print("Weight :",weight[i])
        print("Height :",height[i])
        i += 1

def find_numAge_lessthan30(age):
    i = 0
    count = 0
    while(i < len(age)):
        if(age[i] < 30):
            count += 1
        i += 1
    return count

def insertionSort_byAge(name,ID,age,weight,height):
    for i in range(1,len(age)):
        currentName = name[i]
        currentID = ID[i]
        currentAge = age[i]
        currentWeight = weight[i]
        currentHeight = height[i]

        position = i
        while(position > 0 and age[position-1] > currentAge):
            name[position] = name[position-1]
            ID[position] = ID[position-1]
            age[position] = age[position-1]
            weight[position] = weight[position-1]
            height[position] = height[position-1]
            position = position-1
           
        name[position] = currentName
        ID[position] = currentID
        age[position] = currentAge
        weight[position] = currentWeight
        height[position] = currentHeight


setup()

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

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