1. 程式人生 > 實用技巧 >css背景圖片位置:background的position

css背景圖片位置:background的position

import time
#
def print_info():
    print("=" * 30)
    print("歡迎使用學生管理系統")
    print("1. 新增學生資訊")
    print("2. 修改學生資訊")
    print("3. 刪除學生資訊")
    print("4. 查詢學生資訊")
    print("5. 計算平均年齡")
    print("6. 退出系統")
    print("=" * 30)


def add_student():  # 新增學生資訊
    global student_info  # 宣告函式中要修改的是全域性變數student_info
    dict_1 = {}
    name = input("請輸入學生的姓名:")
    age = int(input("請輸入學生的年齡:"))
    sex = input("請輸入學生的性別:")
    id = input("請輸入學生的號碼:")
    dict_1["name"] = name  # 通過key新增value
    dict_1["age"] = age
    dict_1["sex"] = sex
    dict_1["id"] = id
    student_infor.append(dict_1)  # 將字典追加到列表的一個元素


# student_infor = [{'name': 'zhangsna ', 'age': '20', 'sex': 'nv', 'id': '123456y'}]


def alter_student():
    list_2= []
    opp_name = input("請輸入要刪除的學生姓名")
    for i in student_infor:
        for k, v in i.items():
            if k == 'name':
                list_2.append({k: v})
    num_3 = list_2.index({"name": opp_name})


    # global student_infor
    name = input("請輸入新的學生的姓名:")
    if len(name) > 0:
        student_infor[num_3]["name"] = name
    age = input("請輸入新的年齡")
    if len(age) > 0:
        student_infor[num_3]["age"] = age
    id = input("請輸入新的id")
    if len(id) > 0:
        student_infor[num_3]["id"] = id
    sex = input("請輸入新的性別")
    if len(sex) > 0:
        student_infor[num_3]["sex"] = sex


def opp_student():
    list_2 = []
    opp_name = input("請輸入要刪除的學生姓名")
    for i in student_infor:
        for k, v in i.items():
            if k == 'name':
                list_2.append({k: v})
    num_3 = list_2.index({"name": opp_name})
    # global student_infor
    del student_infor[num_3]


def show_student():  # 顯示學生資訊
    num_1=  input("根據序號查詢還是根據姓名查詢(0根據序號,1根據姓名,2顯示所有)")
    if num_1 == "1":
        list_2 = []
        new_name = input("請輸入要查查詢的學生姓名")
        for i in student_infor:
            for k, v in i.items():
                if k == 'name':
                    list_2.append({k: v})
        num_3 = list_2.index({"name": new_name})
        print(student_infor[num_3])



    elif num_1 == "0":
        show_num = int(input("請輸入您要查詢的學生序號:(0代表查詢所有的學生資訊)"))
        if show_num != 0:
            for i, j in student_infor[show_num - 1].items():
                print(i, j)
        elif show_num == 0:

            for temp in student_infor:  # 遍歷列表
                m = 1  # 索引
                for x, y in temp.items():
                    print(m, x, y)
                    m += 1
            time.sleep(2)
    elif num_1 == "2":
        print(student_infor)
    else:
        print("輸入錯誤")

def age_1():
    m = 0
    n = 0
    for i in student_infor:
        for v in i.values():
            if type(v) == int:
                # print(v)
                m += v
                n += 1

    print(m / n)


student_infor = []


while True:
    print_info()
    choise = int(input('請輸入您要選擇的操作:(1~5)'))
    if choise in [1, 2, 3, 4, 5, 6]:
        print("您選擇的操作是", choise)
        if choise == 6:
            print("感謝使用該程式")
            num_1 = input("您確定要退出程式嗎:(y/n)")
            if num_1 == "y":
                break
            elif num_1 == "n":
                continue
        elif choise == 1:
            print("您選擇的操作是1")
            add_student()
            print(student_infor)
        elif choise == 2:
            print("您選擇的操作是修改學生資訊")
            alter_student()
            print(student_infor)
        elif choise == 3:
            print("您選擇的操作是刪除學生資訊")
            opp_student()
        elif choise == 4:
            print("您選擇的操做是檢視學生資訊")
            show_student()

        elif choise == 5:
            print("您選擇的是計算平均年齡")
            age_1()

    else:
        print("輸入有誤請重新輸入")