python怎么实现银行管理系统

  介绍

小编给大家分享一下python怎么实现银行管理系统,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!

test1用来存类和函数

# test1.py    import  random  #用来随机产生卡号   import  pickle  #序列化,用来存放和取出产生的用户数据   import  os  #产生文件   import  re  #正则表达式,用来判断身份证和手机号,其他地方也可以使用   class 卡:   ,def  __init__(自我,cardId,密码,钱=0):   self.cardId=cardId   self.password=密码   self.money=钱   class 用户(卡):   ,def  __init__(自我,用户名、电话、uid、卡):   self.username=用户名   self.phone=电话   self.uid=uid   用户,self.user_card=card  #继承卡对象   class 银行(用户):# Bank 继承用户,银行是序列化的对象,所以将其变为字典   ,def  __init__(自我、用户):   ,self.cardId=user.user_card.cardId    ,self.user=user    ,self.users={self.cardId: self.user}, #键,卡号,:值,用户对象,      def  generate_cardid(): #方法一,产生卡号   ,列表=[]   ,for 小姐:拷贝范围(0,11):   ,n=random.randint (0, 9)   ,n=str (n)   ,list.append (n)   ,# str=啊? join(列表)   return 列表   #,generate_cardid ()   #,user_cardId=输入(“请输入您的账号:“)   def  create_user(): #方法2:开的户   ,while 真正的:   ,uid=输入(“请输入身份证:“)   ,realut=re.fullmatch (“\ d {17} (\ d X)“, uid), #正则判断身份证是否合理   ,if  realut:   ,uid=realut.group ()   ,打破   ,其他的:   ,打印(“格式不合法“)   ,继续   ,用户名=输入(“请输入姓名:“)   ,while 真正的:   ,电话=输入(“请输入手机号码:“)=,,realut  re.fullmatch (“1 \ d{10},,,电话),#正则判断手机号是否合理,其他需要判断的地方都可以判断,我就不再使用了   ,if  realut:   ,电话=realut.group ()   ,# print(电话)   ,打破   ,其他的:   ,打印(“格式不合法“)   ,继续   ,列表=generate_cardid(), #得到卡号列表   ,cardId=?”; . join(列表),#将卡号变成字符串,字符串的卡号才能做成键   ,打印(f"您的卡号为:{cardId}“)   ,while 真正的:   ,密码=输入(“请输入密码:“)   ,2=输入(“再次输入密码确认:“)   ,if ==密码2:   密码=密码   ,打破   ,else :   ,打印(“两次密码不同,请重新输入!“)   ,继续   ,卡=卡(cardId密码),   ,用户=用户(uid、用户名、电话、卡)   ,银行=银行(用户)#产生银行对象   ,with 开放(f"数据\ \ {cardId} .txt",“ab"), as  file_w:, #重点:创建一个文件夹数据来存放产生的银行对象,每个对象根据卡号产生一个txt文件,用来存放用户的所有数据   ,pickle.dump(银行,file_w), #将bank 序列化保存到文档中   #,create_user ()      def 用户_ (user_cardId): #登录      ,if  os.path.exists (f"数据\ \ {user_cardId} .txt"):   ,with 开放(f"数据\ \ {user_cardId} .txt",,“rb"), as  file_r:=,,u_data  pickle.load (file_r), #根据卡号取出txt文档,反序列化取出数据   ,if  u_data.cardId ==, user_cardId:, # u_data是一个字典,键是卡号,值是用户对象,   n =, 1   ,while 真正的:   ,if  n  & lt;=, 3:=,user_pw 输入(“请输入密码:“)   ,if  u_data.user.user_card.password ==, user_pw:   return 真正的   ,其他的:   ,打印(“密码错误!“)   n +=1   ,继续   ,其他的:   ,打印(“三次输入密码错误!“)   ,返回   ,其他的:   ,打印(“没有该用户“)      #,用户_ (user_cardId)   def  save_money (user_cardId): #,方法4:存的钱   ,if 用户_ (user_cardId):, #如果登录成功   ,钱=int(输入(“请您输入存钱金额:“))   ,with 开放(f"数据\ \ {user_cardId} .txt",,“rb"), as  file_r:=,,u_data  pickle.load (file_r)   u_data.user.user_card.money=u_data.user.user_card.money +钱   ,打印(“您的余额为:“,u_data.user.user_card.money)   ,with 开放(f"数据\ \ {user_cardId} .txt",,“wb"), as  file_w:, #这里要用白平衡,而不是ab,改变数据后,需要覆盖原来的数据,而不是添加   ,pickle.dump (u_data, file_w)   #,save_money ()      def  withdraw_money (user_cardId): #,方法5:取钱   ,if 用户_ (user_cardId):   ,钱=int(输入(“请您输入取款金额:“))   ,with 开放(f"数据\ \ {user_cardId} .txt",,“rb"), as  file_r:=,,u_data  pickle.load (file_r)   ,if  money> u_data.user.user_card.money:   ,打印(“余额不足“)   ,其他的:   u_data.user.user_card.money=u_data.user.user_card.money-money   ,打印(“您的余额为:“,,u_data.user.user_card.money)   ,with 开放(f"数据\ \ {user_cardId} .txt",,“wb"), as  file_w:   ,pickle.dump (u_data, file_w)      #,withdraw_money ()      def  transfer_accounts (user_cardId): #方法6转账   ,if 用户_ (user_cardId):   ,with 开放(f"数据\ \ {user_cardId} .txt",,“rb"), as  file_r:=,,u_data  pickle.load (file_r)   ,while 真正的:=,int, money (输入(“请您转账取款金额:“))   ,if  money 祝辞,u_data.user.user_card.money:   ,打印(“余额不足“)   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

python怎么实现银行管理系统