100-071

编写input()和output()函数输入,输出5个学生的数据记录。
 1 #! /usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 '''
 4 编写input()和output()函数输入,输出5个学生的数据记录。
 5 '''
 6 class Student:
 7     name = ""
 8     age = 0
 9     score = [None] * 4
10 
11     def input(self):
12         self.name = input("Input name, please: ")
13         self.age = int(input("Input age, please: "))
14         for i in range(len(self.score)):
15             self.score[i] = int(input("Input %d score, please: " % (i + 1)))
16 
17     def output(self):
18         print ('Output name: %s' % self.name)
19         print ('Output age: %d' % self.age)
20         for i in range(len(self.score)):
21             print ('Output %d score: %d' % ((i + 1), self.score[i]))
22 
23 
24 if __name__ == "__main__":
25     N = 5
26     studentArray = [Student()] * N
27     for i in range(len(studentArray)):
28         studentArray[i].input()
29 
30     for i in range(len(studentArray)):
31         studentArray[i].output()

 

posted @ 2018-06-04 19:52  睡到自然醒的猪  阅读(68)  评论(0)    收藏  举报

iaoexl at outlook dot com, 返回顶部 →友情链接: 信息港 同城信息