stu_list = []
class student(object):
def __init__(self, name, age):
self.name = name
self.age = age
def get_name(self):
return self.name
def get_age(self):
return self.age
def get_stu(self):
for i, item in enumerate(stu_list):
id = i + 1
name = item[0]
age=stu_list[i][1]
print("姓名:", name, "年龄:", age, "学号:", id, )
def get():
while True:
a=student(input("姓名:"),eval(input("年龄:")))
m=a.get_name()
n=a.get_age()
print(m)
c=stu_list.append((m,n))
print(stu_list)
b=input("是否继续进行:Y/N")
student.get_stu(c)
if b=='b':
break
get()
写成这样,这题有其他的写法吗,在线求助在线求助
[此贴子已经被作者于2022-10-17 13:21编辑过]