class student:
def __init__(self,names,idno,ages,he ,we ):
self.names = names
self.idNo = idno
self.age = ages
self.weight = we
self.height = he
def display(self):
print('Name :',self.names,' ID NO.:',self.idNo,' Age :',self.age,' Weight :',self.weight,' Height :',self.height)
def get_age(self):
return self.age
def get_names(self):
return self.names
def setup():
a= [student('James',58001,13,177,90),
student('Jane',58002,35,140,60),
student('John',58003,17,156,54),
student('Jonas',58004,40,188,70)]
i=0
while(i<len(a)):
a[i].display()
print()
i=i+1
print('the avg of age is',cal_avgAge(a))
findLess30(a)
def cal_avgAge(a):
sums=0
i=0
while(i<len(a)):
ages=a[i].get_age()
sums=sums+ages
avg=sums/len(a)
i=i+1
return avg
def findLess30(a):
i=0
n=0
while(i<len(a)):
ages=a[i].get_age()
names=a[i].get_names()
if(ages<30):
n=n+1
print(names,'is younger than 30')
i=i+1
print('there are ',n,'students < 30')
setup()
ไม่มีความคิดเห็น:
แสดงความคิดเห็น