def __init__(self, st_name, st_id, st_age, st_weight, st_height):
self.name = st_name
self.id = st_id
self.age = st_age
self.weight = st_weight
self.height = st_height
def stData(self):
print("Name :",self.name)
print("ID :",self.id)
print("Age :",self.age)
print("Weight :",self.weight)
print("Height :",self.height)
def getWeight(self):
return self.weight
def getHeight(self):
return self.height
def getAge(self):
return self.age
def getID(self):
return self.id
def setup():
tar = student("tar",10012,21,69,179)
tape = student("tape",10032,21,90,174)
bas = student("bas",10075,19,69,175)
top = student("top",10091,21,92,178)
karn = student("karn",10130,18,60,184)
st_record = [top,tape,tar,karn,bas]
displayStData(st_record)
showBmi(st_record)
showAge(st_record)
sortRecord(st_record)
stWeight(st_record)
def displayStData(student):
i = 0
while i < len(student):
student[i].stData()
print("------------------------")
i+=1
def showBmi(student):
i = 0
count = 1
while i < len(student):
#bmi=float("{0:.2f}".format(student[i].getWeight()/((student[i].getHeight()/100)**2)))
bmi=float(format(student[i].getHeight()/((student[i].getHeight()/100)**2),'.2f'))
#bmi = student[i].getWeight()/(student[i].getHeight()/100)**2
if bmi > 25:
print("No :",count)
student[i].stData()
print("Bmi :",bmi)
print("------------------------")
count+=1
i+=1
def showAge(student):
i = 0
count = 0
sum_age = 0
while i < len(student):
sum_age += student[i].getAge()
if student[i].getAge() < 30:
count+=1
i+=1
avg_age = sum_age/len(student)
print("Average age of students :",avg_age)
print("------------------------")
def sortRecord(student):
i = 0
while i < len(student) :
if i!=len(student)-1 and student[i].getAge() > student[i+1].getAge():
j = i
while j >= 0:
if student[j].getAge() > student[j+1].getAge():
dataCopy = student[j]
student[j] = student[j+1]
student[j+1] = dataCopy
j-=1
else :
break
i+=1
print("Sort record by age")
print("------------------------")
displayStData(student)
def stWeight(student):
i = 0
count = 1
min_weight = student[0].getWeight()
while i < len(student):
if student[i].getWeight() < min_weight:
min_weight = student[i].getWeight()
if student[i].getWeight() < 70:
print("No :",count)
student[i].stData()
print("------------------------")
count+=1
i+=1
print("Minimum weight of students :",min_weight)
print("------------------------")
setup()
ไม่มีความคิดเห็น:
แสดงความคิดเห็น