学生系统Pro

master
HJW20 2 months ago
parent b541fd5e60
commit a45b465868

@ -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:

@ -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
}
]

@ -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}"

@ -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()}")

Loading…
Cancel
Save