day12-作業(yè)

"""author = Zard"""

學(xué)生管理系統(tǒng)

import json
with open('files/stu_info.json', 'r', encoding='utf-8') as f:
    content = f.read()
    stu_add = json.loads(content)

gen1 = (x for x in range(1,10000))
# 試圖寫返回函數(shù),失敗。
# def wyk_back():
#     print('‖=================華麗的分割線=================‖')
#     print('1.繼續(xù)')
#     print('2.返回')
#     x = input('請選擇:')
#     if int(x) == 2:
#         m = 0

# 增加學(xué)生
def wyk_insert():

    m = 1
    while m:
        # 此處有難點,添加的學(xué)生學(xué)號保存不了---使用生成器解決
        stu_info = {}
        print('‖=================添加學(xué)生==================‖')
        stu_info["姓名"] = input('輸入學(xué)生姓名:')
        stu_info["年齡"] = input('輸入學(xué)生年齡:')
        stu_info["電話"] = input('輸入學(xué)生電話:')
        stu_info["學(xué)號"] = str(next(gen1)).zfill(4)
        stu_add.append(stu_info)
        for i in stu_add:
            print(i)

        print('‖==================添加成功==================‖')
        print('1.繼續(xù)')
        print('2.返回')
        x = input('請選擇:')
        if int(x) == 2:
            m = 0



# 刪除學(xué)生
def wyk_delete():
    del_stu = input('‖============請輸入刪除學(xué)生的姓名或?qū)W號:')
    for u in stu_add:
        if del_stu == u['姓名'] or del_stu == u['學(xué)號']:
            stu_add.remove(u)
            for i in stu_add:
                print(i)
            break


# 查看學(xué)生
def wyk_look():
    m = 1
    while m:
        for i in stu_add:
            print(i)
        print('‖=================華麗的分割線=================‖')
        print('1.繼續(xù)')
        print('2.返回')
        x = input('請選擇:')
        if int(x) == 2:
            m -= 1


# 修改學(xué)生
def wyk_recom():
    m = 1
    while m:
        recom_stu = input('‖============請輸入需要修改的學(xué)生姓名或?qū)W號:')
        for y in stu_add:
            if recom_stu == y['姓名'] or recom_stu == y['學(xué)號']:
                print('‖=================修改學(xué)生==================‖')
                y['姓名'] = input('輸入學(xué)生姓名:')
                y['年齡'] = input('輸入學(xué)生年齡:')
                y['電話'] = input('輸入學(xué)生電話:')
                for i in stu_add:
                    print(i)
                print('‖=================華麗的分割線=================‖')
                print('1.繼續(xù)')
                print('2.返回')
                x = input('請選擇:')
                if int(x) == 2:
                    m -= 1

# 操作頁面
def stu_op(x):
    m = 1
    while m:
        print('‖================================================‖')
        print('‖????歡迎來到藍翔技術(shù)學(xué)院學(xué)生管理中心????‖')
        print('‖歡迎技師: %s !                                ‖' % x)
        print('‖                                                ‖')
        print('‖              ★ 1.添加                         ‖')
        print('‖              ★ 2.查看                         ‖')
        print('‖              ★ 3.修改                         ‖')
        print('‖              ★ 4.刪除                         ‖')
        print('‖              ★ 5.返回                         ‖')
        print('‖================================================‖')
        add_wyk = input('請輸入您的選擇(1-5):')
        if int(add_wyk) == 1:
            wyk_insert()
        if int(add_wyk) == 2:
            wyk_look()
        if int(add_wyk) == 3:
            wyk_recom()
        if int(add_wyk) == 4:
            wyk_delete()
        if int(add_wyk) == 5:
            break

f1 = open('./files/id_bank','r',encoding='utf-8')
id_bank = eval(f1.read())
f1.close()

# 登錄
def login():
    while True:
        stu_id = input('‖============登陸中=========請輸入★賬號★:')
        stu_pw = input('‖===========登陸中=========請輸入★密碼★:')
        if stu_id in id_bank and str(id_bank[stu_id]) == stu_pw:
            print('‖===================登錄成功==================‖')
            stu_op(stu_id)

            break
        else:
            print('‖===登錄失敗,賬戶或者密碼有誤!請重新輸入===‖')
            break
# 注冊
def register():
    while True:
        re_id = input('‖==========請輸入您的注冊賬號========(字母或數(shù)字):')
        if  not ( 2 <= len(re_id) <= 20 and( 'a' < re_id < 'z' or 'A' <
            re_id < 'Z' or '0' < re_id < '9' or '\u4e00' < re_id < '\u9fa5')):
            print('‖=======輸入有誤,請重新輸入具體賬號信息!=======‖')
            continue
        if re_id in id_bank:
            print('‖===========賬號已存在,請重新輸入!=============‖')
            continue
        if 1 <= len(re_id) <= 10:
            re_pw = input('‖=========請輸入您的注冊密碼========(字母或數(shù)字):')
            for x in re_pw:
                if  not ( 6 <= len(re_pw) <= 12 and( 'a' < re_pw < 'z' or
                        'A' < re_pw < 'Z' or '0' < re_pw < '9')):
                    print('‖==密碼設(shè)置有誤,請重新輸入(不能帶漢字,6-12位)==‖')
                    break
            else:
                print('‖==============注冊成功,請重新登錄=============‖')
                id_bank[re_id] = re_pw
                with open('./files/id_bank','w',encoding='utf-8') as f:
                    f.write(str(id_bank))
                login()
        else:
            print('‖=========賬號輸入有誤請重新輸入(1-10位)=========‖')

# 開始頁面
def begin():
    count_out = 5
    while count_out:
        print('‖================================================‖')
        print('‖????歡迎來到藍翔技術(shù)學(xué)院學(xué)生管理中心????‖')
        print('‖````````````````````````````````````````````````‖')
        print('‖                                                ‖')
        print('‖                                                ‖')
        print('‖              ★ 1.登錄 ★                      ‖')
        print('‖            ★★ 2.注冊 ★★                    ‖')
        print('‖          ★★★3.打擾了★★★                  ‖')
        print('‖                                                ‖')
        print('‖================================================‖')
        with open('./files/stu_info.json', 'w', encoding='utf-8') as f:
            content1 = json.dumps(stu_add)
            f.write(content1)
        choice = input('請輸入您的選擇(1-3):')
        if int(choice) == 1:
            login()
        if int(choice) == 2:
            register()
        if int(choice) == 3:
            count_out -= 1
            if count_out == 0:
                print('‖==============**!***!*****!!sb吧!=============‖')
                break
            print('‖========請繼續(xù)!再接再厲,您還有%s次機會=========‖' % (count_out))
            continue
        else:
            print('‖===============輸入有誤,請重新嘗試==============‖')
            continue

begin()
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • -- coding: utf-8 --"""File Name: day12作業(yè)Author : ...
    LPP27149閱讀 309評論 0 6
  • 作業(yè):學(xué)生管理做添加學(xué)生的模塊,a登錄成功 -> 學(xué)生管理 -> 添加學(xué)生到賬號a中。
    Gary134閱讀 195評論 0 0
  • """author = 曹琦""" 作業(yè):輸入年齡并且將年齡值轉(zhuǎn)換成整數(shù),如果輸入錯誤程序不崩潰,讓其重新輸入,知...
    曹琦777閱讀 243評論 0 1
  • 5.寫一個類,封裝所有和數(shù)學(xué)運算相關(guān)的功能 5-160.6666666666666666208 redblue美國...
    曉曉的忍兒閱讀 457評論 0 14
  • 聲明一個電腦類:屬性:品牌、顏色、內(nèi)存大小方法:打游戲、寫代碼、看視頻a.創(chuàng)建電腦類的對象,然后通過對象點的方式獲...
    舊時初_2e8d閱讀 129評論 0 3

友情鏈接更多精彩內(nèi)容