# -*- conding:utf-8 -*- ''' kind: Create a bank class Attributes: A class attribute that belongs to Bank Used to store all bank account opening information, including card number, password, user name, balance (The outside world cannot access and modify it at will. When opening an account, you need to verify the card number to check whether the card number already exists) Every object has Card number, password, username, balance (The outside world cannot freely access and modify it.) Method: Bank Class Owned Check the total number of accounts opened in this bank View personal information of all users (including card number, password, username, balance) Every object has Pass in the relevant parameters when instantiating the object Initialize object and class properties Withdraw money (requires card number and password verification) Operate the individual's balance by verifying the card number and password. If the amount of money withdrawn is greater than the balance, it will return insufficient balance. Deposit money (requires card number and password verification) Operate the personal balance by verifying the card number and password, and return success View personal trust information (requires card number and password verification) Return personal card number, user name, balance information ''' class Bank: #Create a class attribute, __Users = { } #The dictionary is used to store meeting information of all banks, including card number, password, username, balance def __init__ (self,carId,userName,pwd,balance): if carId not in Bank .__Users : Bank.__Users[carId]={'userName':userName,'pwd':pwd,'balance':balance} self.__userName = userName self.__pwd = pwd self. __balance = balance #View the total number of accounts opened in this bank @classmethod #Class method def nums(cls): num = len(cls. __Users ) print ( ' The total number of bank accounts: %d ' % num) #View the personal information of all users (including card number, password, username, balance) @classmethod def get_user(cls): for key ,val in cls. __Users .items(): print ( ' Card number: %s \nUser name: %s \nPassword: %s \nBalance: %d \n ' %(key,val[ ' userName ' ] ,val[ ' pwd ' ],val[ ' balance ' ])) #Verification method @staticmethod def check_user(carId,pwd): if ( (carId in Bank. __Users ) and (pwd == Bank. __Users [carId][ ' pwd ' ]) ): return True else : return False #Verify the amount @staticmethod def check_money(money): if isinstance(money,int): return True else : return False #Withdraw money (requires card number and password verification) def q_money(self,carId,pwd,money): if Bank.check_user(carId,pwd): if Bank.check_money(money): if Bank.__Users[carId]['balance']>=money: Bank. __Users [carId][ ' balance ' ] -= money print ( ' Current card number %s, current withdrawal amount %d, current balance %d ' %(carId, money, Bank. __Users [carId][ ' balance ' ] )) else : print ( ' Insufficient amount ' ) else : print ( ' The amount you entered is incorrect! ' ) else : print ( ' The card number or password is wrong!') #存钱 def c_money(self,carId,pwd,money): if Bank.check_user(carId,pwd): if Bank.check_money(money): Bank .__Users [ carId ][ ' balance ' ] += money print ( ' Current card number %s, current deposit amount %d, current balance %d ' %(carId,money,Bank .__Users [carId][ ' balance ' ] )) else : print ( ' The amount you entered is wrong! ' ) else : print ( ' The card number or password is wrong! ' ) #View personal details (requires card number and password verification) def getInfor(self,carId,pwd): ifBank.check_user(carId,pwd): print ( ' Current card number %s, current deposit amount %d, current balance %d ' %(carId,money,Bank. __Users [carId][ ' balance ' ])) else : print ( ' The card number or password is wrong! ' ) xuyg = Bank ( ' 0000 ' , ' xuyg ' , ' 123 ' , 100 ) xuyg.nums() xuyg.get_user() xuyg.q_money('0000','123',50) xuyg.c_money('0000','123',500)