函数求助
有没有大佬能解释一下为什么函数同时返回两个值会被调用两次呢 啥叫调用两次,函数里面的两个print语句明显是调试代码,属于多余的 wp231957 发表于 2020-12-16 07:34啥叫调用两次,函数里面的两个print语句明显是调试代码,属于多余的
运行是这样的,他会连续调用两次,跟print没关系 去你妈的编程梦 发表于 2020-12-16 08:23
运行是这样的,他会连续调用两次,跟print没关系
你不上代码 鬼知道你是如何调用的呢 wp231957 发表于 2020-12-16 08:38
你不上代码 鬼知道你是如何调用的呢
不好意思哈,第一次求助,待会我回去了就发代码{:10_254:}{:10_254:} wp231957 发表于 2020-12-16 08:38
你不上代码 鬼知道你是如何调用的呢
import pymysql
import random
import sys
import easygui as eg
#密码字符串
id_ = '0123456789'
#检查密码是否一致
def chack(a,b):
if a == b:
return 1
else:
eg.msgbox(msg='两次输入不一致,请重新输入')
return 0
#生成随机卡号
def card_id_random():
bank_id = ''
# 生成随机银行号码,并检查是否在数据库中
for i in range(8):
bank_id += random.choice(id_)
return bank_id
#生成新用户信息
def to_info():
info = ['姓名','身份证号码','电话号码','密码','再次输入密码','存款金额']
total_msg = eg.multenterbox(msg='请填写以下信息',title='创建新用户',fields=info)
#检查两次密码是否一致
while True:
if chack(total_msg,total_msg):
break
else:
total_msg = eg.enterbox(title='创建新用户',msg='两次密码不一致,请重新输入')
# money =float(input('请输入你想存入的金额'))
bank_id = ''
# 生成随机银行号码,并检查是否在数据库中
while True:
bank_id = card_id_random()
#print(bank_id)
cs.execute("select * from user")
result = cs.fetchall()
if bank_id in result:
pass
else:
break
#插入数据
s1 = "insert intouser VALUES ('{}',{},{},{})".format(total_msg,total_msg,total_msg,bank_id)
con.commit()#提交数据
s2 = "insert intocard VALUES ({},{},{},{})".format(bank_id,total_msg,total_msg,1)
con.commit()
cs.execute(s1)
con.commit()
cs.execute(s2)
con.commit()
eg.msgbox(msg=f'你好{total_msg},你的银行卡号是{bank_id}')
#返回单个用户信息(未输入密码)
#res_1是用户信息,res_2是卡的信息
def search(a = 0):
try:
bank_id = eg.enterbox(msg='请输入你的卡号')
if chack_card_lock(bank_id) or a == 1:
cs.execute(sql_6.format(bank_id))
result_1 = cs.fetchone()
eg.msgbox(msg=f'你好{result_1}')
cs.execute(sql_5.format(bank_id))
result_2 = cs.fetchone()
return result_1, result_2
else:
eg.msgbox(msg='此卡已被上锁,不能进行任何操作')
except:
eg.msgbox(msg='账户不存在')
#检查密码
def enter_password():
result_1, result_2 = search()
password = eg.enterbox(msg='请输入你的密码,共有5次机会')
i = 5
while True:
if int(password) == result_2:
return 1
else:
i-=1
password = eg.enterbox(msg=f'输入错误,请重新输入,还有{i}次机会')
return 0
#查询余额
def cer_search():
try:
result_1,result_2 = search()
if enter_password():
eg.msgbox(msg=f'你的余额为:{result_2}')
except:
print('账户不存在')
#存钱
def load_in():
result_1, result_2 = search()
if enter_password():
money = float(eg.enterbox(msg='请输入你要存款的金额'))
money += result_2
cs.execute("update card set money = {} where card_id = {}".format(money,result_1))
con.commit()
cs.execute(sql_5.format(result_1))
con.commit()
temp = cs.fetchone()
eg.msgbox(msg=f'存款成功,你目前剩余的金额为{temp}')
#取钱
def load_out():
result_1, result_2 = search()
if enter_password():
out = float(eg.enterbox(msg='请输入你要取出的金额'))
temp = result_2 - out
if temp >= 0:
cs.execute("update card set money = {} where card_id = {}".format(temp,result_1))
con.commit()
eg.msgbox(msg=f'取款成功,你当前可用余额为{temp}')
else:
eg.msgbox(msg='余额不足')
#转账
def move():
result_1, result_2 = search()
if enter_password():
eg.msgbox(msg=f'你剩余的金额为{result_2}')
z_id = int(eg.enterbox(msg='请输入你要转入的账户'))
try:
#获取接收转账账户的信息
cs.execute("select * from card where card_id = {} ".format(z_id))
con.commit()
res = cs.fetchone()
m_money = float(eg.enterbox(msg='请输入转账的金额'))
if m_money>result_2:
eg.msgbox(msg='余额不足')
else:
temp = result_2-m_money
temp_ = res + m_money
eg.msgbox(msg="正在转账....")
cs.execute("update card set money = {} where card_id = {}".format(temp,result_1))
con.commit()
cs.execute("update card set money = {} where card_id = {}".format(temp_,res))
con.commit()
eg.msgbox(msg=f"转账成功")
except:
eg.msgbox(msg='你输入的账户不存在!')
#修改密码
def change_password():
result_1, result_2 = search()
if enter_password():
eg.msgbox(msg=f'你的余额为{result_2}')
new_password = eg.enterbox(msg='请输入你的新密码')
while True:
password_ = eg.enterbox(msg='请再次输入密码')
if chack(new_password,password_):
break
cs.execute("update card set password = {} where card_id = {}".format(new_password,result_1))
con.commit()
eg.msgbox(msg="修改成功")
#锁卡
def lock_card():
result_1, result_2 = search()
if enter_password():
en = eg.enterbox(msg="是否确认锁卡(YES/NO)?")
if en == 'yes':
cs.execute("update card set mention = {} where card_id = {}".format(0,result_1))
con.commit()
else:
pass
#开卡
def unlock_card():
try:
result_1, result_2 = search(a = 1)
if enter_password():
en = eg.enterbox(msg="是否确认开卡(YES/NO)?")
if en == 'yes':
cs.execute("update card set mention = {} where card_id = {}".format(1,result_1))
con.commit()
else:
pass
except:
pass
#检查是否锁卡
defchack_card_lock(card_num):
cs.execute("select * from card where card_id ={}".format(card_num))
con.commit()
res = cs.fetchone()
if res == 0:
return 0
return 1
#补卡
def rep_card():
result_1, result_2 = search()
if enter_password():
bank_id = card_id_random()
eg.msgbox(msg="正在创建...")
s = "insert intocard VALUES ({},{},{},{})".format(bank_id, result_2,result_2, 1)
s1 = "insert intouser VALUES ('{}',{},{},{})".format(result_1,result_1,result_1,bank_id)
cs.execute(s)
con.commit()
cs.execute(s1)
con.commit()
eg.msgbox(msg="创建成功")
cs.execute("delete from card where card_id= {}".format(result_1))
con.commit()
cs.execute("delete from user where bank_id= {}".format(result_1))
con.commit()
#销户
def drop_user():
result_1, result_2 = search()
if enter_password():
ensure = eg.enterbox(msg=f"是否要注销账户{result_1}(yes/no)")
if ensure == 'yes':
eg.msgbox(msg="正在删除...")
cs.execute("delete from card where card_id = {}".format(result_1))
con.commit()
cs.execute("delete from user where bank_id = {}".format(result_1))
con.commit()
eg.msgbox(msg="删除成功")
#退出
def quit():
sys.exit()
#与数据库建立连接
con = pymysql.connect('localhost','root','000000','bank')
#建立游标
cs = con.cursor()
#sql语句 建表
sql = """
create table card(
card_id int(100) ,
password int(100) ,
money FLOAT (20) ,
mention int(1))
"""
sql_1= """
create table user(
name varchar(100),
id_card varchar(100),
tel varchar(100),
bank_idint(100))
"""
# sql_2 = 'insert intouser VALUES (%s,%s,%s,%s)'
# sql_3 = 'insert intocard VALUES (%s,%s,%s,%s)'
sql_4 ="select * from user"
sql_5 = "select * from card where card_id = {} "
sql_6 = "select * from user where bank_id = {}"
sql_7 = "update card set money = {} where bank_id = {}"
# sql_8 = "update card set money -= {} where bank_id = {}"
sql_9 = "update card set mention = {} where bank_id = {}"
choice_dict = {'开户':1,'查询':2,'存款':3,'取款':4,'转账':5,'改密':6,'锁卡':7,'解锁':8,'补卡':9,'销户':10,'退出':'q'}
#修改表,让其可以插入中文
# cs.execute(sql)
# cs.execute(sql_1)
cs.execute("alter table user convert to character set utf8mb4 collate utf8mb4_bin")
cs.execute("alter table card convert to character set utf8mb4 collate utf8mb4_bin")
while True:
op = eg.buttonbox(msg = """ ************************************
*************主功能*************
*****开户(1) 查询(2)*****
*****存款(3) 取款(4)*****
*****转账(5) 改密(6)*****
*****锁卡(7) 解锁(8)*****
*****补卡(9) 销户(0)*****
*************退出(q)************
************************************
""",title='请选择功能',choices=['开户','查询','存款','取款','转账','改密','锁卡','解锁','补卡','销户','退出'])
op = str(choice_dict)
if op == '1':
to_info()#测试完成
elif op == '2':
cer_search()
elif op == '3':
load_in()
elif op == '4':
load_out()
elif op == '5':
move()
elif op == '6':
change_password()
elif op == '7':
lock_card()
elif op == '8':
unlock_card()
elif op == '9':
rep_card()
elif op == '0':
drop_user()
elif op == 'q':
quit()
else:
eg.msgbox(msg='非法输入!')
# con.commit()
# con.close() wp231957 发表于 2020-12-16 08:38
你不上代码 鬼知道你是如何调用的呢
是我自己调用了两次,哈哈,已经解决了
页:
[1]