1. 程式人生 > 實用技巧 >redis 常見問題

redis 常見問題

題目要求
編寫一個ATM管理系統,語言不限,要求應包括以下主要功能:
(1)開戶,銷戶
(2)查詢賬戶餘額
(3)存款
(4)取款
(5)轉賬(一個賬戶轉到另一個賬戶)等...、
1.連線MySQL資料庫、建立資料表、給資料表中插入資料:
import MySQLdb

conn = MySQLdb.connect(host='127.0.0.1',port=3306,user='root',passwd='971012',db='test',charset="utf8") #連線mysql資料庫
cursor = conn.cursor()
sql = '''CREATE TABLE IF NOT EXISTS userinfoes (
user VARCHAR(20),
password VARCHAR(6),
age VARCHAR(3),
sex VARCHAR(5),
mobile VARCHAR(11),
balance FLOAT(12,2))'''
cursor.execute(sql)
sql = '''INSERT INTO userinfoes(user,
password,age,sex,mobile,balance)
VALUES ('luu','123456','19','woman','12345678900',10000)'''
cursor.execute(sql)
2.實現登入驗證
def login():
print u'請輸入你的使用者名稱:'
k=3
while k:
global username
username = raw_input()
if username == '':
print u'使用者名稱不能為空!'
elif j == 0:
k-=1
if k!=0:
print u'使用者名稱錯誤,請重新輸入:'
else:
print u'你已輸錯三次!'
conn.close()
cursor.close()
exit()
else:
break
print u'請輸入你的密碼:'
k = 3
while k:
password = raw_input()
userinfoes = "SELECT * FROM userinfoes WHERE user='%s' and password='%s'"%(username,password)
j = cursor.execute(userinfoes)

if password == '':
    print u'密碼不能為空!'
elif j == 0:
    k-=1
    if k!=0:
        print u'密碼錯誤,請重新輸入:'
    else:
        print u'你已輸錯三次!'
        conn.close()
        cursor.close()
        exit()
else:
    print u'恭喜你,登入成功!'
    break

3.實現使用者註冊
def enroll():

print u'請輸入使用者名稱(長度<=20):' #使用者名稱
while 1:
username = raw_input()
userinfoes = "SELECT * FROM userinfoes WHERE user='%s'"%username
j = cursor.execute(userinfoes)
if j1:
print u'該使用者名稱已經存在,請重新輸入!'
elif username'':
print u'使用者名稱不能為空!'
else:
break
4.系統退出

conn.close()
cursor.close()
5.主選單介面
def Home_page():
print u''歡迎使用ATM存取款系統
def judge1():
Home_page()
while 1:
judge_1 = raw_input()