From a45b46586818c4a6e052c6620711be7e4b3ba0f1 Mon Sep 17 00:00:00 2001 From: HJW20 <1264519711@qq.com> Date: Thu, 26 Jun 2025 11:21:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AD=A6=E7=94=9F=E7=B3=BB=E7=BB=9FPro?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 学生系统AA版本/bll/validators.py | 4 ++-- 学生系统AA版本/students.json | 15 +++++++++++++++ 学生系统AA版本/ui/console_ui.py | 14 +++++++------- 学生系统AA版本/utils/id_card.py | 23 ++++++++++++----------- 4 files changed, 36 insertions(+), 20 deletions(-) create mode 100644 学生系统AA版本/students.json diff --git a/学生系统AA版本/bll/validators.py b/学生系统AA版本/bll/validators.py index aee904c..d8d9761 100644 --- a/学生系统AA版本/bll/validators.py +++ b/学生系统AA版本/bll/validators.py @@ -23,8 +23,8 @@ def validate_id_card(id_card: str) -> bool: def validate_stu_id(stu_id: str) -> bool: """验证学号有效性""" - # 假设学号格式为: 年份(4位)+学院代码(2位)+专业代码(2位)+序号(3位) - return len(stu_id) == 11 and stu_id.isdigit() + # 假设学号格式为: 15位数的那个学号 + return len(stu_id) == 15 and stu_id.isdigit() def validate_name(name: str) -> bool: diff --git a/学生系统AA版本/students.json b/学生系统AA版本/students.json new file mode 100644 index 0000000..175abb9 --- /dev/null +++ b/学生系统AA版本/students.json @@ -0,0 +1,15 @@ +[ + { + "name": "德国", + "id_card": "510703200411220010", + "stu_id": "110309230907004", + "gender": true, + "height": 177, + "weight": 60.0, + "enrollment_date": "2023-09-01", + "class_name": "困", + "major": "碎觉", + "birthday": "2004-11-22", + "age": 20 + } +] \ No newline at end of file diff --git a/学生系统AA版本/ui/console_ui.py b/学生系统AA版本/ui/console_ui.py index b482c4b..152825f 100644 --- a/学生系统AA版本/ui/console_ui.py +++ b/学生系统AA版本/ui/console_ui.py @@ -54,24 +54,24 @@ def _input_student_info(update_mode=False) -> Optional[Student]: id_card = input("身份证号: ").strip() if not update_mode else None stu_id = input("学号: ").strip() if not update_mode else None - gender_input = input("性别(男/女, 可选): ").strip().lower() + gender_input = input("性别(男/女): ").strip().lower() gender = None if gender_input == '男': gender = True elif gender_input == '女': gender = False - height_input = input("身高(cm, 可选): ").strip() + height_input = input("身高(cm): ").strip() height = int(height_input) if height_input else None - weight_input = input("体重(kg, 可选): ").strip() + weight_input = input("体重(kg): ").strip() weight = float(weight_input) if weight_input else None - enrollment_date_input = input("入学日期(YYYY-MM-DD, 可选): ").strip() + enrollment_date_input = input("入学日期(YYYY-MM-DD): ").strip() enrollment_date = date.fromisoformat(enrollment_date_input) if enrollment_date_input else None - class_name = input("班级名称(可选): ").strip() or None - major = input("专业(可选): ").strip() or None + class_name = input("班级名称: ").strip() or None + major = input("专业: ").strip() or None if update_mode: return Student( @@ -115,7 +115,7 @@ def _display_students_list(students: list[Student]): for student in students: gender = '男' if student.gender else '女' if student.gender is not None else '未知' print( - f"{student.stu_id:<12}" + f"{student.stu_id:<16}" f"{student.name:<10}" f"{gender:<6}" f"{student.age:<6}" diff --git a/学生系统AA版本/utils/id_card.py b/学生系统AA版本/utils/id_card.py index 4588cb0..7020b16 100644 --- a/学生系统AA版本/utils/id_card.py +++ b/学生系统AA版本/utils/id_card.py @@ -149,7 +149,17 @@ def get_region_from_id_card(id_card: str) -> Tuple[str, str]: '310000': ('上海市', '上海市'), '310100': ('上海市', '上海市'), '440000': ('广东省', ''), - '440300': ('广东省', '深圳市'), + '510000': ('四川省', ''), + '510700': ('四川省', '绵阳市'), + '510703': ('四川省', '绵阳市'), + '510704': ('四川省', '绵阳市'), + '510705': ('四川省', '绵阳市'), + + + + + + # Add more regions as needed... } @@ -168,7 +178,7 @@ def generate_test_id_card() -> str: # Region code (random Beijing district) region = '110' + str(random.randint(100, 199))[:3] - # Birth date (18-60 years old) + # Birth_date (18-60 years old) birth_year = date.today().year - random.randint(18, 60) birth_date = f"{birth_year}{random.randint(1, 12):02d}{random.randint(1, 28):02d}" @@ -188,14 +198,5 @@ def generate_test_id_card() -> str: return first_17 + checksum -# Example usage -if __name__ == "__main__": - test_id = "110105199003078888" # Example valid ID - print(f"Validate ID: {validate_id_card(test_id)}") - print(f"Birth date: {extract_birthday_from_id_card(test_id)}") - print(f"Age: {calculate_age(extract_birthday_from_id_card(test_id))}") - print(f"Gender: {'Male' if get_gender_from_id_card(test_id) else 'Female'}") - print(f"Region: {get_region_from_id_card(test_id)}") - print(f"Test ID: {generate_test_id_card()}")