Sunday, October 25, 2015

Lab6 - Display student records, sorted by age, use insertion sort

def setup():
    name = ["Ant", "Bird" ,"Cat" ,"Dog" ,"Elephant" ,"Frog" ,"Giraffe"]
    id = [19, 23 ,10 ,13 ,22 ,25 ,17]
    age = [18 ,17 ,16 ,19 ,18 ,18 ,17]
    weight = [58, 62 ,60 ,72 ,55 ,55 ,50]
    height = [169, 170 ,172 ,188 ,165 ,158 ,160]
    display(name,id,age,height,weight)
   
def display(name,id,age,height,weight):
    index=0
    while(index<len(age)):
        index1=index+1
        while(index1<len(age)):
            if(age[index]>age[index1]):
                temp=age[index]
                age[index]=age[index1]
                age[index1]=temp
            index1+=1
        index+=1
    index=0
    print("-sorted by age-")
    print("")
    while(index<len(age)):
        index1=0
        stop = False
        while(index1<len(age) and (not stop)):
            if(age[index1]==age[index]):
                print("Name ",name[index])
                print("ID ",id[index])
                print("Age ",age[index])
                print("Weight ",weight[index])
                print("Height ",height[index])
                print("")
                stop=True
            index1+=1
        index+=1
       
setup()
           

No comments:

Post a Comment