python3 實戰項目系列之 三


python 實戰案例三:  學生管理系統設計與實現(完善中。。。。)

# -*- coding:utf-8 -*-


import sys
import pandas as pd
from sqlalchemy import create_engine
import MySQLdb

reload(sys)
sys.setdefaultencoding('utf-8')


'''
設計開發一套學生信息管理系統,具備以下功能:
1、權限管理:學生,管理員
2、注冊,用戶名,密碼登陸
3、學生具備登陸,查詢個人信息,成績的權限
4、新用戶注冊,將注冊信息持久化到mysql 學生信息表
5、老用戶(學生信息表里面有記錄的學生)

'''

'''***打印功能列表***'''
def showinfo():
    print "學生管理系統 V1.0"
    print "\t1:登陸系統"
    print "\t2:注冊賬號"
    print "\t3:興趣選課"
    print "\t4:成績查詢"
    print "\t5:愛師選評"
    print "\t0:退出系統"


'''***功能選擇***'''
def getinfo():
    choince = input("請按提示選擇:")
    return int(choince)


'''***登陸,注冊***'''
def User_Login():
    sno = input("請輸入你的學號:")
    passwd = input("請輸入密碼:")

    # 判斷是否為新用戶
    for i in range(0, 3, 1):
        i = i + 1
        if str(sno) == "123456" and str(passwd) == '123':
            print "歡迎進入學生管理系統!"
        else:
            print "您尚未開通權限,請注冊!"
            new_sno = input("\n\t請輸入賬號(學號):")
            new_passwd = input("\t為你賬號設置密碼:")
            again_new_passwd = input("\t請再次輸入密碼:")
            if str(new_passwd) == str(again_new_passwd):
                print "注冊成功!"
                showinfo()

            else:
                print "兩次密碼不一致,請重新輸入"
                continue


'''***登陸mysql***'''
def login_mysql():
    # 創建連接
    conn = MySQLdb.Connect(host='127.0.0.1'
                           , user='root'
                           , passwd='1234563'
                           , db='student'
                           , port=3306
                           , charset='utf8'
                           )

    # 創建查詢入口
    cur = conn.cursor(MySQLdb.cursors.DictCursor)

    # 執行sql
    cur.execute()

    # 獲取數據
    processResult = cur.fetchall()

    # 關閉 cur
    cur.close()

    # 關閉 conn
    conn.close()

def score():
    sql_sc = "select * from student_score"
    rest = login_mysql().cur().execute(sql_sc)
    return rest


def student_info():
    sql_info = "select * from student_info"
    info = login_mysql().cur().execute(sql_info)
    return info



def to_mysql(dataframe):
    connect = create_engine('mysql+mysqldb://root:123456@127.0.0.1:3306/student?charset=utf8')
    pd.io.sql.to_sql(dataframe
                     , "student_info"
                     , con=connect
                     , schema="student"
                     , if_exists="append"
                     )

def quitInfo():
    print("退出系統!")



if __name__ == '__main__':
    while True:
        showinfo()
        key = getinfo()
        if key == 0:
            quitInfo()
            break
        elif key == 1:
            getinfo()
        elif key == 2:
            User_Login()
        elif key == 3:
            print "成績查詢"
        elif key == 4:
            score()
        else:
            print "請重新輸入!!!"

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM