def __init__(self,name,weight,high,age,ID):
self.name = name
self.weight = weight
self.high = high
self.age = age
self.ID = ID
def show_data(self):
print("Name",self.name)
print("Weight",self.weight)
print("High",self.high)
print("Age",self.age)
print("ID",self.ID)
def get_age(self):
return self.age
def age(data):
age = data.get_age()
return age
def average_age(data):
index = 0
summation = 0
while(index<len(data)):
summation += age(data[index])/4
index = index + 1
return summation
def find_age(data):
index = 0
while(index<len(data)):
if(age(data[index])<30):
print(age(data[index]),end = " ")
index = index + 1
def count_age(data):
index = 0
count = 0
while(index<len(data)):
if(age(data[index])<30):
count +=1
index = index + 1
return count
def setup():
index= 0
data = [student("Keane",50,185,18,1),
student("Giggs",55,175,19,2),
student("Nani",40,160,20,3),
student("Park",45,169,18,4),
student("Rooney",80,150,20,5)]
while(index<len(data)):
data[index].show_data()
index = index + 1
print("Average age is",average_age(data),"years old")
print("Display the age that under 30 years old")
find_age(data)
print()
print("The number of age that under 30 years old is",count_age(data))
setup()
ไม่มีความคิดเห็น:
แสดงความคิดเห็น