请设计一个类,记录学生的: 姓名、年龄、地址,这3类信息 请实现: 通过for循环,配合input输入语句,并使用构造方法,完成学生信息的键盘录入 ,输入完成后,使用print语句,完成信息的输出 当前录入第1位学生信息,总共需录入10位学生信息
时间: 2024-03-13 14:46:47 浏览: 102
好的,我可以帮您设计这个类和完成录入输出操作。请参考下面的代码:
```python
class Student:
def __init__(self, name, age, address):
self.name = name
self.age = age
self.address = address
# 创建一个空列表,用于存储学生对象
students = []
# 循环录入学生信息
for i in range(1, 11):
print("当前录入第{}位学生信息:".format(i))
name = input("请输入学生姓名:")
age = input("请输入学生年龄:")
address = input("请输入学生地址:")
# 创建一个学生对象并添加到列表中
student = Student(name, age, address)
students.append(student)
# 循环输出学生信息
for i, student in enumerate(students):
print("第{}位学生信息:".format(i+1))
print("姓名:{}".format(student.name))
print("年龄:{}".format(student.age))
print("地址:{}".format(student.address))
```
运行代码后,您可以依次输入每个学生的姓名、年龄和地址,最终输出所有学生的信息。注意,这里使用了一个空列表来存储学生对象,并使用了一个循环来遍历列表并输出每个学生的信息。
阅读全文
相关推荐
![doc](https://img-home.csdnimg.cn/images/20241231044833.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![-](https://img-home.csdnimg.cn/images/20241226111658.png)
![application/x-rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-c](https://img-home.csdnimg.cn/images/20250102104920.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)