python3实现ATM自助取款机程序
import pymysql
import random
class Atmsql():
def __init__(self):
# 连接mysql数据库 localhost:连接本地数据库
self.data = pymysql.connect(host="localhost", user="root", password="123456", database="gangge")
# 创建一个游标来执行sql
self.cursor = self.data.cursor()
# 获取atm库中所有卡号
def atm_card(self):
sql_card = 'select 卡号 from atm;'
self.cursor.execute(sql_card)
card = self.cursor.fetchall()
list_card = []
for i in card:
for j in i:
list_card.append(j)
return list_card
# 根据输入卡号获取余额
def atm_money(self,card):
sql_money = 'select 余额 from atm where 卡号="{}"; '.format(card)
self.cursor.execute(sql_money)
tuple_money = self.cursor.fetchone()
for money in tuple_money:
return money
# 根据输入卡号获取密码
def atm_password(self,card):
sql_pwd = 'select 密码 from atm where 卡号="{}"; '.format(card)
self.cursor.execute(sql_pwd)
tuple_pwd = self.cursor.fetchone()
for pwd in tuple_pwd:
return pwd
# 根据输入卡号获取卡状态
def atm_islock(self,card):
sql_islock = 'select 卡状态 from atm where 卡号="{}"; '.format(card)
self.cursor.execute(sql_islock)
tuple_islock = self.cursor.fetchone()
for islock in tuple_islock:
return islock
# 根据输入卡号获取账户名
def atm_name(self, card):
sql_pwd = 'select 账户名 from atm where 卡号="{}"; '.format(card)
self.cursor.execute(sql_pwd)
tuple_name = self.cursor.fetchone()
for name in tuple_name:
return name
# 根据输入卡号获取身份证
def atm_sfz(self, card):
sql_sfz = 'select 身份证 from atm where 卡号="{}"; '.format(card)
self.cursor.execute(sql_sfz)
tuple_sfz = self.cursor.fetchone()
for sfz in tuple_sfz:
return sfz
# 根据输入卡号修改卡状态
def new_islock(self,islock,card):
sql_islock = 'update atm set 卡状态={} where 卡号="{}";'.format(islock,card)
self.cursor.execute(sql_islock)
self.data.commit()
# 根据输入卡号修改卡余额
def new_money(self,money,card):
money = 'update atm set 余额="{}" where 卡号="{}";'.format(money,card)
self.cursor.execute(money)
self.data.commit()
# 根据输入卡号修改卡密码
def new_pwd(self, pwd, card):
pwd = 'update atm set 密码="{}" where 卡号="{}";'.format(pwd,card)
self.cursor.execute(pwd)
self.data.commit()
# 根据输入卡号修改卡号 # 避免一个身份证只能办一张卡的问题
def new_sql_card(self,card,new_card):
sql_id = 'select id from atm where 卡号="{}"; '.format(card)
self.cursor.execute(sql_id)
tuple_id = self.cursor.fetchone()
for id in tuple_id:
sql_card = 'update atm set 卡号="{}" where id={};'.format(new_card,id)
self.cursor.execute(sql_card)
self.data.commit()
# 用户名检测
def user_name(sel