Import pymysqlconn=pymysql.connect (host= ' 192.168.8.30 ', port=3306,user= ' root ', password= ' 123456 ', db= ' hzdl ', charset= ' UTF8 ') cur=conn.cursor () while True: #提示用户输入账号 print (' Please enter account: ') #接收用户的输入 name=input () #提示用户输入密码 PR int (' Please enter password: ') #接收用户的输入 password=input () #进行账号, password checksum #输出校验结果 result=cur.execute (' select * from User_info whe Re name=%s ', name) if Result==0:print ("Account Not Present") Else:user=cur.fetchone () if User[1]!=password: Print (' password incorrect ') else:print (' login successful ') breakwhile true:print (' Please select service 1-check balance 2-Withdrawal 3- Transfer 0-exit ') Choice=input () if choice== ' 1 ': #余额查询时, you need to read the latest data from the database again Cur.execute (' select * from User_info Where name=%s ', name) User=cur.fetchone () print (' Current account balance:%s '%user[2]) if choice== ' 2 ': #进行取款交易前, again from the data The library reads the latest data Cur.execute (' select * from User_info where name=%s ', name) User=cur.fetchone () print (' Please enter the withdrawal money Amount: ') money=float (input ()) IF money%50!=0:print (' illegal amount ') elif money>1000:print (' cannot exceed single limit ') Elif Money>user [2]: print (' Insufficient balance ') Else:result=user[2]-money cur.execute (' Update user_info set mo ney=%s where name=%s ', [result,user[0]]) conn.commit () print (' Current account balance:%s '%result) if choice== ' 3 ': #进行取款交易前, read the latest data from the database again Cur.execute (' select * from User_info where name=%s ', name) User=cur.fetchone () Print (' Please enter beneficiary account: ') name2=input () result2=cur.execute (' select * from User_info where name=%s ', name2) If Result2==0:print (' Collection account Not Present ') Else:user2=cur.fetchone () print (' Beneficiary account exists, start Transfer Transaction ') print (' Please enter transfer amount: ') money2=float (input ()) if Money2>2000:print (' No can exceed a single limit ') Elif money2>user[2]: print (' Insufficient balance ') else:result3=user[2]- Money2 RESult4=user2[2]+money2 cur.execute (' Update user_info set money=%s where name=%s ', [result3,user[0]]) Cur.execute (' Update user_info set money=%s where name=%s ', [result4,user2[0]]) conn.commit () Print (' Current account balance:%s '%result3) if choice== ' 0 ': Break cur.close () Conn.close ()
RECORD-11 program Practice, Cash Machine (database)