最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用Python實現(xiàn)簡單的學生成績管理系統(tǒng)

 更新時間:2022年01月25日 15:05:12   作者:迢迢x  
這篇文章主要為大家詳細介紹了Python實現(xiàn)學生成績管理系統(tǒng),使用數(shù)據(jù)庫,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

基本功能:

  • 能夠?qū)崿F(xiàn)學生成績相關信息的輸入、輸出、查找、刪除、修改等功能;(使用數(shù)據(jù)庫對數(shù)據(jù)進行存?。?/li>
  • 輸入并存儲學生的信息:通過輸入學生的學號、姓名、和分數(shù),然后就可以把數(shù)據(jù)保存在建立的student文件里面。
  • 打印學生的所有信息:通過一個打印函數(shù)就可以把所有的信息打印在屏幕上。
  • 查找學生信息:這個功能通過輸入學號,查找該學生的信息,如果有該學號就輸出該學生的信息,沒有該學號就提示輸入的學號不存在。
  • 刪除學生信息:該功能是對相應的學生進行刪除操作,如果學生存在就查找到進行刪除。
  • 修改學生信息:這個功能首先通過查詢功能查詢出該學生是否存在,如果存在就對該學生的信息進行修改,如果不存在則返回到主界面。

實現(xiàn)效果:

制作技巧  

1.定義變量

(1)定義交互輸入變量

主要用于展示學生成績管理系統(tǒng)的操作界面。

(2)定義學生成績信息變量

主要用于學生成績信息的存取。

s_info = """
*****************************************************
【學生成績管理系統(tǒng)】
                            q. 退出學生成績系統(tǒng)
                            1. 顯示學生成績信息
                            2. 新建學生成績信息                            
                            3. 查詢學生成績信息
                            4. 刪除學生成績信息
                            5. 修改學生成績信息
******************************************************"""
    students=[]

2.讀取學生成績信息

主要是從TXT文件中讀取學生成績信息,并保存到學生成績變量中。

f=open("students.txt","r+")
    for st in f.readlines():
        students.append(eval(st))
    f.close()

3.循環(huán)等待操作指令并執(zhí)行

主要是循環(huán)等待輸入的學生管理系統(tǒng)操作指令,獲取到操作指令后執(zhí)行對學生成績信息的顯示、新建、查詢、刪除、修改操作。

while True:
        print(s_info)
        handle = input('請選擇你要的操作選項:')
        if handle == 'q':
            print('q. 退出系統(tǒng)')
            break
        elif handle == '1':            
            s_display(students)
        elif handle == '2':
            s_new(students)
        elif handle == '3':
            s_find(students)       
        elif handle == '4':
            s_delect(students)
        elif handle == '5':
            s_modify(students)         
        else:
            print('請輸入正確的操作選項!')

4.編寫操作指令執(zhí)行函數(shù)

(1)顯示學生成績信息函數(shù)

主要功能是顯示所有學生成績信息。

def s_display(students):
        print('1. 顯示全部信息')
        print('姓名\t語文\t數(shù)學\t英語\t總分')
        for stu in students:
            print(f'{stu["name"]}\t{stu["chinese"]}\t{stu["math"]}\t{stu["english"]}\t{stu["total"]}')

(2)新建學生成績信息函數(shù)

主要是新建學生成績信息,并更新保存學生成績信息的文件。

def s_new(students):
        print('2. 新建學生信息')
        name = str(input('請輸入學生的姓名:'))
        chinese = int(input('請輸入學生的語文成績:'))
        math = int(input('請輸入學生的數(shù)學成績:'))
        english = int(input('請輸入學生的英語成績:'))
        total = chinese + math + english
        stu = {'name': name, 'chinese': chinese, 'math': math, 'english': english, 'total': total}
        students.append(stu)
        s_write_to_file(students)

(3)查詢學生成績信息函數(shù)

主要是查詢給定姓名的學生成績信息。

 
def s_find(students):
        print('3. 查詢學生信息')
        name = input('請輸入你要查詢學生的姓名:')
        for stu in students:
            if name == stu['name']:
                print('姓名\t語文\t數(shù)學\t英語\t總分')
                print(f'{stu["name"]}\t{stu["chinese"]}\t{stu["math"]}\t{stu["english"]}\t{stu["total"]}')
                break
        else:
            print('該學生不存在, 請檢查名字是否輸入正確!')
        s_write_to_file(students)

(4)刪除學生成績信息函數(shù)

主要是刪除給定姓名的學生成績信息,并更新保存學生成績信息的文件。

def s_delect(students):
        print('4. 刪除學生信息')
        name = input('請輸入你要刪除學生的姓名:')
        for stu in students:
            if name == stu['name']:
                students.remove(stu)
                break
        else:
            print('該學生不存在, 請檢查名字是否輸入正確!')
        s_write_to_file(students)

(5)修改學生成績信息函數(shù)

主要是修改給定姓名的學生成績信息,并更新保存學生成績信息的文件。

 
def s_modify(students):
        print('5. 修改學生信息')
        name = input('請輸入你要修改學生的姓名:')
        for stu in students:
            if name == stu['name']:
                print('(如果不想修改,直接回車!)')
                name = input('請重新輸入學生的姓名:')
                chinese = input('請重新輸入學生的語文成績:')
                math = input('請重新輸入學生的數(shù)學成績:')
                english = input('請重新輸入學生的英語成績:')
                if name:
                    stu['name'] = str(name)
                if chinese:
                    stu['chinese'] = int(chinese)
                if math:
                    stu['math'] = int(math)
                if english:
                    stu['english'] = int(english)
                stu['total'] = stu['chinese'] + stu['math'] + stu['english']
                break
        else:
            print('該學生不存在, 請檢查名字是否輸入正確!')
        s_write_to_file(students)

5.保存學生成績信息函數(shù)

主要實現(xiàn)學生成績信息的保存更新。

 
def s_write_to_file(students):
        f=open("students.txt","r+")
        for s  in students:
            f.write(str(s)+"\n")
        f.close()

完整源代碼

def s_write_to_file(students):
        f=open("students.txt","r+")
        for s  in students:
            f.write(str(s)+"\n")
        f.close()
def s_display(students):
        print('1. 顯示全部信息')
        print('姓名\t語文\t數(shù)學\t英語\t總分')
        for stu in students:
            print(f'{stu["name"]}\t{stu["chinese"]}\t{stu["math"]}\t{stu["english"]}\t{stu["total"]}')
def s_new(students):
        print('2. 新建學生信息')
        name = str(input('請輸入學生的姓名:'))
        chinese = int(input('請輸入學生的語文成績:'))
        math = int(input('請輸入學生的數(shù)學成績:'))
        english = int(input('請輸入學生的英語成績:'))
        total = chinese + math + english
        stu = {'name': name, 'chinese': chinese, 'math': math, 'english': english, 'total': total}
        students.append(stu)
        s_write_to_file(students)
def s_find(students):
        print('3. 查詢學生信息')
        name = input('請輸入你要查詢學生的姓名:')
        for stu in students:
            if name == stu['name']:
                print('姓名\t語文\t數(shù)學\t英語\t總分')
                print(f'{stu["name"]}\t{stu["chinese"]}\t{stu["math"]}\t{stu["english"]}\t{stu["total"]}')
                break
        else:
            print('該學生不存在, 請檢查名字是否輸入正確!')
        s_write_to_file(students)
def s_delect(students):
        print('4. 刪除學生信息')
        name = input('請輸入你要刪除學生的姓名:')
        for stu in students:
            if name == stu['name']:
                students.remove(stu)
                break
        else:
            print('該學生不存在, 請檢查名字是否輸入正確!')
        s_write_to_file(students)
def s_modify(students):
        print('5. 修改學生信息')
        name = input('請輸入你要修改學生的姓名:')
        for stu in students:
            if name == stu['name']:
                print('(如果不想修改,直接回車!)')
                name = input('請重新輸入學生的姓名:')
                chinese = input('請重新輸入學生的語文成績:')
                math = input('請重新輸入學生的數(shù)學成績:')
                english = input('請重新輸入學生的英語成績:')
                if name:
                    stu['name'] = str(name)
                if chinese:
                    stu['chinese'] = int(chinese)
                if math:
                    stu['math'] = int(math)
                if english:
                    stu['english'] = int(english)
                stu['total'] = stu['chinese'] + stu['math'] + stu['english']
                break
        else:
            print('該學生不存在, 請檢查名字是否輸入正確!')
        s_write_to_file(students)
if __name__=="__main__":
    s_info = """
*****************************************************
【學生成績管理系統(tǒng)】
                            q. 退出學生成績系統(tǒng)
                            1. 顯示學生成績信息
                            2. 新建學生成績信息                            
                            3. 查詢學生成績信息
                            4. 刪除學生成績信息
                            5. 修改學生成績信息
******************************************************"""
    students=[]
    f=open("students.txt","r+")
    for st in f.readlines():
        students.append(eval(st))
    f.close()
    while True:
        print(s_info)
        handle = input('請選擇你要的操作選項:')
        if handle == 'q':
            print('q. 退出系統(tǒng)')
            break
        elif handle == '1':            
            s_display(students)
        elif handle == '2':
            s_new(students)
        elif handle == '3':
            s_find(students)       
        elif handle == '4':
            s_delect(students)
        elif handle == '5':
            s_modify(students)         
        else:
            print('請輸入正確的操作選項!')

總結(jié)

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關注腳本之家的更多內(nèi)容!

相關文章

最新評論

仪陇县| 桐城市| 滕州市| 黄骅市| 封丘县| 竹北市| 玉环县| 博白县| 喀喇| 南阳市| 邵阳市| 招远市| 安丘市| 新闻| 延寿县| 呼玛县| 太仆寺旗| 靖江市| 三河市| 横山县| 葵青区| 肃宁县| 绥德县| 米易县| 康定县| 登封市| 忻城县| 重庆市| 卢湾区| 固原市| 徐闻县| 福清市| 鸡西市| 山西省| 漠河县| 灵丘县| 都江堰市| 浏阳市| 界首市| 外汇| 宾阳县|