题目:编写input()和output()函数输入,输出5个学生的数据记录。
解释:可以通过函数的方式实现,也可以用类的方式实现,下面举例用类的方法实现:
class Student:
name = ""
age = 0
score = [None] * 4
def input(self):
self.name = input("Input name, please: ")
self.age = int(input("Input age, please: "))
for i in range(len(self.score)):
self.score[i] = int(input("Input %d score, please: " % (i + 1)))
def output(self):
print ('Output name: %s' % self.name)
print ('Output age: %d' % self.age)
for i in range(len(self.score)):
print ('Output %d score: %d' % ((i + 1), self.score[i]))
if __name__ == "__main__":
N = 5
studentArray = [Student()] * N
for i in range(len(studentArray)):
studentArray[i].input()
for i in range(len(studentArray)):
studentArray[i].output()
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)