def setup():
names=["Jack",'John','James','Jane']
idNo=['5801','5802','5803','5804']
age=[18,32,15,41]
weight=[60,99,72,50]
height=[150,162,170,159]
listthedata(names,idNo,age,weight,height)
print(lessage30(names,age),'student < 30')
print('the avg age is',find_avgAge(names,age))
sortByAge(names,age)
def listthedata(names,idNo,age,weight,height):
i=0
while(i<len(names)):
print('Name : ',names[i],' ID NO.: ',idNo[i],' Age: ',age[i])
print('Weight: ',weight[i],' Height: ',height[i],' BMI: %.2f'%cal_bmi(i,weight,height))
print()
i=i+1
def sortByAge(names,age):
j=1
while(j<len(age)):
n=age[j]
i=j-1
while(i >= 0) and (age[i] > n):
age[i+1]=age[i]
i=i-1
age[i+1] = n
j=j+1
print(age)
def cal_bmi(i,weight,height):
bmi=(weight[i])/((height[i]/100)**2)
return bmi
def lessage30(names,age):
i=0
sums=0
while(i<len(names)):
if(age[i]<30):
sums=sums+1
i=i+1
return sums
def find_avgAge(names,age):
i=0
sums=0
while(i<len(names)):
sums=sums+age[i]
i=i+1
avg=sums/len(names)
return avg
setup()
ไม่มีความคิดเห็น:
แสดงความคิดเห็น