运行结果:
源代码:
"""
项目:类似于学生管理系统---增删改查
"""
#封装一个学生类
import random
class Student:
def __init__(self,stuid,name,score):
self.stuid = stuid
self.name = name
self.score = score
def show_info(self):
print(f"{self.stuid},{self.name},{self.score}")
stu_list=[]
#生成学号,4位数随机的,唯一的
def get_stuid():
while True:
#产生一个随机学号
stu_id = random.randint(1000,9999)
#遍历学生list,查看学号是否被占用
for stu in stu_list:
if stu.stuid == stu_id:#占用
break;
else:
return stu_id