class Account: def init(self, name, balance=0): self.name = name self.balance = balance self.status = 'normal'

def deposit(self, amount):
    self.balance += amount

def withdraw(self, amount):
    if self.balance < amount:
        print('Insufficient balance')
    else:
        self.balance -= amount

def query_balance(self):
    print('Your balance is', self.balance)

def lose_card(self):
    self.status = 'lost'

def find_card(self):
    self.status = 'normal'

def close_account(self):
    self.status = 'closed'

@staticmethod
def login(username, password):
    # 模拟用户名和密码的验证过程
    if username == 'user' and password == 'password':
        return True
    else:
        return False

def main(): # 模拟银行账户系统 accounts = {} while True: print('Welcome to the bank') print('1. Open account') print('2. Deposit') print('3. Withdraw') print('4. Check balance') print('5. Lose card') print('6. Find card') print('7. Close account') print('8. Exit') choice = input('Enter your choice: ') if choice == '1': name = input('Enter your name: ') balance = 1000 # 默认开户时余额为1000元 account = Account(name, balance) accounts[name] = account # 保存账户信息 print('Your account has been opened') elif choice == '2': name = input('Enter your name: ') amount = int(input('Enter the amount to deposit: ')) account = accounts.get(name) if account: account.deposit(amount) print('Your deposit has been successful') else: print('Account does not exist') elif choice == '3': name = input('Enter your name: ') amount = int(input('Enter the amount to withdraw: ')) account = accounts.get(name) if account: account.withdraw(amount) print('Your withdrawal has been successful') else: print('Account does not exist') elif choice == '4': name = input('Enter your name: ') account = accounts.get(name) if account: account.query_balance() else: print('Account does not exist') elif choice == '5': name = input('Enter your name: ') account = accounts.get(name) if account: account.lose_card() print('Your card has been lost') else: print('Account does not exist') elif choice == '6': name = input('Enter your name: ') account = accounts.get(name) if account: account.find_card() print('Your card has been found') else: print('Account does not exist') elif choice == '7': name = input('Enter your name: ') account = accounts.get(name) if account: account.close_account() del accounts[name] print('Your account has been closed') else: print('Account does not exist') elif choice == '8': break # 退出程序 else: print('Invalid choice')

if name == 'main': main(

class Accountdef __init__self name balance=0selfname = nameselfbalance = balanceselfstatus = normaldef depositself amountselfbalance += amountdef withdrawself amountif selfbalance amountprintInsuffic

原文地址: https://www.cveoy.top/t/topic/hlox 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录