forked from yangdd1205/python3-100-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example71.py
61 lines (45 loc) · 1.46 KB
/
example71.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python3
__author__ = "yang.dd"
"""
example 071
"""
class Student(object):
def __init__(self):
self.__num = 0
self.__name = ""
self.__score = [0, 0, 0, 0]
def get_num(self):
return self.__num
def get_name(self):
return self.__name
def get_score(self):
return self.__score
def set_name(self, name):
self.__name = name
def set_num(self, num):
try:
num = int(num)
self.__num = num
except ValueError as e:
print("Please input a int")
def set_score(self, score_1, score_2, score_3, score_4):
self.__score[0] = score_1
self.__score[1] = score_2
self.__score[2] = score_3
self.__score[3] = score_4
def input_stu(n):
student_list = []
for i in range(n):
s = Student()
s.set_num(input("请输入编号:"))
s.set_name(input("请输入姓名:"))
s.set_score(input("请输入成绩1:"), input("请输入成绩2:"), input("请输入成绩3:"), input("请输入成绩4:"))
student_list.append(s)
return student_list
def output_stu(student_list):
for i in range(len(student_list)):
s = student_list[i]
print("编号:%s\t姓名:%s\t成绩[%s\t%s\t%s\t%s]" % (
s.get_num(), s.get_name(), s.get_score()[0], s.get_score()[1], s.get_score()[2], s.get_score()[3]))
if __name__ == '__main__':
output_stu(input_stu(1))