需实现:①通过for循环,配合input输入语句,并使用构造方法,完成学生信息的键盘录入;
②输入完成后,使用print语句,完成信息的输出。
class Student:
def __int__(self, na, ag, personal_plac):
self.name = na
self.age = ag
self.personal_place = personal_plac
d = {}
for i in range(10):
print(f"当前录入第{i}位学生信息,总共需要录入10位学生信息")
name = input("请输入学生的姓名:")
age = input("请输入学生的年龄:")
personal_place = input("请输入学生的地址:")
d['stu'+str(i)] = Student(name, age, personal_place)
print(f"学生{i}信息录入完成,信息为{d[i]}")
刚开始学基础课程,还没能完全学懂,试过了网上能找到的相似的方法,但是还是没能解决。
如果有了解此类问题的解决方法的,请提供一下解题思路,感谢!
class Student:
def __init__(self, na, ag, personal_plac):
self.name = na
self.age = ag
self.personal_place = personal_plac
def Print(self):
print("【学生姓名:{},年龄:{},地址:{}】".format(self.name,self.age,self.personal_place))
d = {}
for i in range(10):
print(f"当前录入第{i}位学生信息,总共需要录入10位学生信息")
name = input("请输入学生的姓名:")
age = input("请输入学生的年龄:")
personal_place = input("请输入学生的地址:")
d[i] = Student(name, age, personal_place)
print(f"学生{i}信息录入完成,信息为:",end='')
d[i].Print()
这题有其他的解法,用字典,列表都可以,不过你的这个用类也是可以的,不过,你的语法格式有问题,改一下你的实例对象格式,以及输出的格式就可以了。