วันอาทิตย์ที่ 25 ตุลาคม พ.ศ. 2558

LAB 7 Show data + creat class

def setup():
   a = student("hydya",10164,30,150)
   b = student("ameba",10165,35,160)
   c = student("tic",10166,40,170)
   d = student("toc",10167,50,160)
   data_student = [a,b,c,d]
   display_array(data_student)

def display_array(data):
   count = 0
   while(count<len(data)):
      data[count].show_data()
      count += 1
 
 
class student:
   def __init__(self,name,iD,weight,height):
      self.name = name
      self.iD   = iD
      self.weight = weight
      self.height = height
 
   def show_data(self):
      print(">>>>>>>>>><<<<<<<<<<<<")
      print("Student name ",self.name)
      print("    id    is ",self.iD)
      print("weight is ",self.weight)
      print("height  is ",self.height)
 
setup()

ผลลัพธ์

>>>>>>>>>><<<<<<<<<<<<
Student name  hydya
    id    is  10164
weight is  30
height  is  150
>>>>>>>>>><<<<<<<<<<<<
Student name  ameba
    id    is  10165
weight is  35
height  is  160
>>>>>>>>>><<<<<<<<<<<<
Student name  tic
    id    is  10166
weight is  40
height  is  170
>>>>>>>>>><<<<<<<<<<<<
Student name  toc
    id    is  10167
weight is  50
height  is  160

ไม่มีความคิดเห็น:

แสดงความคิดเห็น