python 银行管理系统
这是一个使用python连接mysql的例子
涉及到类的使用
import pymysql
import function as f
def mysql():
db=pymysql.connect(host='localhost',user='root',password='1234',charset='utf8')
cursor=db.cursor()
cursor.execute('create database bank;')
cursor.execute('use bank')
sql='''
create table account(account_id varchar(50),
account_passwd char(6),
money decimal(10,2)
)default charset=utf8;
'''
cursor.execute(sql)
sql_insert='''
insert into account values('supermao','200112',10000.00),
('other','123',100.00);
'''
cursor.execute(sql_insert)
db.commit()
def start():
while True:
num=input('欢迎来到银行管理系统 1.登录 2.注册 q.退出:')
if num == '2':
account = f.Account(None,None)
account.touch_character()
print('注册成功')
elif num == 'q':
print('已退出')
break
elif num == '1':
name=input('请输入用户名:')
passwd=input('请输入密码:')
account = f.Account(name, passwd)
account.check_id()
if account.choice == '5':
continue
while True:
account.main()
if account.choice == '4':
break
else:
print('请重新输入')
continue
#mysql()
start()
function.py
import pymysql
db=None
class Account:
def __init__(self,user,passwd):
self.user=user
self.passwd=passwd
self.money_sql="select money from account where account_id='%s' and account_passwd='%s'"\
%(self.user,self.passwd)
def main(self):
global db
db=pymysql.connect(host='localhost', user='root',
password='1234', charset='utf8',database='bank')
self.cursor = db.cursor()
print('1.取钱, 2.查询, 3.存钱, 4.退出')
choice=input('请按序号进行选择:')
if choice == '1':
self.withdraw()
self.choice = choice
if choice == '2':
self.select()
self.choice = choice
if choice == '3':
self.save_money()
self.choice = choice
if choice == '4':
self.exit()
self.choice = choice
def withdraw(self):
self.cursor.execute(self.money_sql)
money=self.cursor.fetchall()
fetch=input('取多少钱?')
self.fin=int(money[0][0])-int(fetch)
if self.fin < 0:
print('余额不足')
else:
update_sql = 'UPDATE account set money=%d where account_id="%s" ' \
'and account_passwd="%s"' % (self.fin, self.user, self.passwd)
self.cursor.execute(update_sql)
db.commit()
def select(self):
self.cursor.execute(self.money_sql)
money=self.cursor.fetchall()
print('当前余额%s'%(money[0][0]))
def save_money(self):
self.cursor.execute(self.money_sql)
money=self.cursor.fetchall()
save=input('存多少钱')
total=int(money[0][0])+int(save)
update_sql2 = "UPDATE account set money=%d where account_id='%s' ' \
'and account_passwd='%s'" % (total, self.user, self.passwd)
self.cursor.execute(update_sql2)
db.commit()
def touch_character(self):
db = pymysql.connect(host='localhost', user='root',
password='1234', charset='utf8', database='bank')
cursor=db.cursor()
user=input('创建用户')
passwd=input('输入用户密码')
sql='''insert into account values('%s','%s',0);'''%(user,passwd)
cursor.execute(sql)
db.commit()
def check_id(self):
db=pymysql.connect(host='localhost', user='root',
password='1234', charset='utf8',database='bank')
self.cursor=db.cursor()
select = '''select * from account where account_id='%s'
and account_passwd='%s';''' % (self.user, self.passwd)
self.cursor.execute('use bank')
self.cursor.execute(select)
if self.cursor.fetchall():
print(' 登录成功')
print('你好%s'%(self.user))
self.choice = '1'
else:
print(' 登录失败')
self.choice = '5'
def exit(self):
self.cursor.close()
db.close()
python 银行管理系统的更多相关文章
- 银行管理系统[C++]
//项目:银行管理系统 //系统实现的主要有管理,取款机管理,用户查询等功能: //*管理模块:存款.取款.开户.销户.修改信息.办卡.挂失卡; //*用户查询模块; //*取款机信息管理模块:管理员 ...
- c++ 银行管理系统及报告
1.题目描写叙述: 本代码为银行管理系统,总体分为管理员模式和普通用户模式: (1)在管理员模式中能完毕 ①用户信息录入 ②改动管理员password ③改动指定账户信息 ④信息管理业务 (2)在普通 ...
- python连接mysql数据库实例demo(银行管理系统数据库版)
主函数: import adminView import os import pickle from bankFunction import BankFunction import time def ...
- python用户管理系统
学Python这么久了,第一次写一个这么多的代码(我承认只有300多行,重复的代码挺多的,我承认我确实垃圾),但是也挺不容易的 自定义函数+装饰器,每一个模块写的一个函数 很多地方能用装饰器(逻辑跟不 ...
- python名片管理系统V2
主程序: #! /usr/bin env python3 # -*- coding: utf-8 -*- # 项目三: # 1.要求:编写一个名片管理系统,功能如下: # 用户输入相对应的指令,实现对 ...
- python名片管理系统
1.代码: (1)主程序 #!/usr/bin/env python # -*- coding: UTF-8 -*- import cards_tools # 无限循环,由用户主动决定什么时候退出循环 ...
- python学生管理系统
import osimport re #获取本机用户名,构建student.txt文件名创建在左面import getpassusername=getpass.getuser()print(" ...
- python员工管理系统(基础版)
各位小伙伴们大家好,最近自学python已经差不多把基础学完了,现在运用这些基础知识写了一个简单版本的员工管理系统 因为在大学里我是学过java的,所以,当有了一定的基础和熏陶外,真心觉得python ...
- Python图书管理系统
图书管理系统 功能简介 添加图书时,图书ID不能重复,图书名可重复 删除,查询,修改功能,输入图书名之后提供所有的同名的图书,用户可以按照图书序号对具体的一本书进行操作 显示书籍,分行显示,每行一本书 ...
随机推荐
- PIC16 bootloader之UART bootloader
了解更多关于bootloader 的C语言实现,请加我Q扣: 1273623966 (验证信息请填 bootloader),欢迎咨询或定制bootloader(在线升级程序). PIC16 bootl ...
- 洛谷 P3994 高速公路(斜率优化)
题目链接 题意:给出一棵树,\(1\) 号点为根,边上有边权. 每个点有两个参数 \(p_i,q_i\) 如果你想从 \(i\) 号点到与其距离为 \(d\) 的 \(j\) 号点,那么你需花费 \( ...
- Codeforces 1464F - My Beautiful Madness(树的直径)
Codeforces 题面传送门 & 洛谷题面传送门 树上数据结构大杂烩(?) 首先考虑什么样的点能够在所有路径的 \(d\) 邻居的交集内.显然如果一个点在一条路径的 \(d\) 邻居内则必 ...
- OpenSSH 密码和公钥认证原理探究
目录 配置和保护SSH H3 - 使用SSH 访问远程命令行 H4 - 什么是OpenSSH ? H4 - 登录方式: H4 - 登录并执行临时命令: H4 - 查看登录用户 H4 - 登录原理 密码 ...
- 03 Windows安装Java环境
Java环境安装 使用微信扫码关注微信公众号,并回复:"Java环境",免费获取下载链接! 1.卸载(电脑未装此程序,跳过此过程) 找到电脑上面的控制面板 找到这两个文 ...
- 学习java 7.27
学习内容: 创建树 Swing 使用JTree对象来代表一棵树,JTree树中结点可以使用TreePath来标识,该对象封装了当前结点及其所有的父结点. 当一个结点具有子结点时,该结点有两种状态: 展 ...
- 如何在 ASP.NET Core 中构建轻量级服务
在 ASP.NET Core 中处理 Web 应用程序时,我们可能经常希望构建轻量级服务,也就是没有模板或控制器类的服务. 轻量级服务可以降低资源消耗,而且能够提高性能.我们可以在 Startup 或 ...
- adult
adult是adolescere (grow up)的过去分词. egg - embryo [胚胎] - foetus [就要出生的胎儿] - toddler [刚会走路] - adolescent ...
- A Child's History of England.20
CHAPTER 7 ENGLAND UNDER HAROLD THE SECOND, AND CONQUERED BY THE NORMANS Harold was crowned King of E ...
- day11 函数
day11 函数 一.函数基础 """ 1 什么是函数 函数是盛放代码的容器:把实现某一功能的代码放到一个函数内就制造一个工具 2 为何要用函数 没有用函数之前程序的问题 ...