-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclass_lianx
More file actions
30 lines (24 loc) · 1.12 KB
/
Copy pathclass_lianx
File metadata and controls
30 lines (24 loc) · 1.12 KB
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
"""
学生信息录入系统,设计一个类,记录学生的:姓名、年龄、地址
"""
# 通过 for 循环,配合 input 输入语句,并使用构造方法,完成信息录入
# 输入完成后,使用 print 语句,完成信息的输入
class Student:
def __init__(self, name, age, addr):
self.name = name
self.age = age
self.addr = addr
# 用列表存储所有学生对象
students = []
for i in range(1, 11):
print(f"当前录入第{i}位学生信息,总共需录入10位学生信息")
input_name = input("请输入学生姓名:")
input_age = input("请输入学生年龄:")
input_addr = input("请输入学生地址:")
# 每次循环创建新的 Student 对象并加入列表
stu = Student(input_name, input_age, input_addr)
students.append(stu)
print(f"学生{i}信息录入完成,信息为:【学生姓名:{stu.name},年龄{stu.age},地址:{stu.addr}】")
print("\n所有学生的信息录入完毕!")
for idx, stu in enumerate(students, 1):
print(f"第{idx}位学生,姓名:{stu.name},年龄:{stu.age},住址:{stu.addr}")