python实现具有账户查询功能:登记账户各项信息,包括:姓名、余额,近一个月的支出和收入,账户挂失;
时间: 2024-03-14 11:48:17 浏览: 43
python实现学生信息管理系统
好的,针对您提出的需求,我可以为您提供一个Python实现的账户查询功能的示例代码。代码如下:
```python
class Account:
def __init__(self, name, balance, transactions=[]):
self.name = name
self.balance = balance
self.transactions = transactions
def deposit(self, amount):
self.balance += amount
self.transactions.append(('deposit', amount))
def withdraw(self, amount):
if self.balance < amount:
print("Insufficient balance")
return
self.balance -= amount
self.transactions.append(('withdraw', amount))
def get_balance(self):
return self.balance
def get_transactions(self):
return self.transactions
def report(self):
print("Account Holder Name:", self.name)
print("Account Balance:", self.balance)
print("Recent Transactions:")
for i in self.transactions:
print(i[0], i[1])
accounts = []
def create_account():
name = input("Enter Account Holder Name: ")
balance = float(input("Enter Initial Balance: "))
account = Account(name, balance)
accounts.append(account)
print("Account Created Successfully")
def deposit():
account_number = int(input("Enter Account Number: "))
amount = float(input("Enter Amount to Deposit: "))
accounts[account_number].deposit(amount)
print("Amount Deposited Successfully")
def withdraw():
account_number = int(input("Enter Account Number: "))
amount = float(input("Enter Amount to Withdraw: "))
accounts[account_number].withdraw(amount)
print("Amount Withdrawn Successfully")
def balance_enquiry():
account_number = int(input("Enter Account Number: "))
balance = accounts[account_number].get_balance()
print("Current Balance:", balance)
def recent_transactions():
account_number = int(input("Enter Account Number: "))
transactions = accounts[account_number].get_transactions()
print("Recent Transactions:")
for i in transactions:
print(i[0], i[1])
def account_report():
account_number = int(input("Enter Account Number: "))
accounts[account_number].report()
def account_menu():
print("Welcome to Account Menu")
print("1. Create Account")
print("2. Deposit")
print("3. Withdraw")
print("4. Balance Enquiry")
print("5. Recent Transactions")
print("6. Account Report")
print("7. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
create_account()
elif choice == 2:
deposit()
elif choice == 3:
withdraw()
elif choice == 4:
balance_enquiry()
elif choice == 5:
recent_transactions()
elif choice == 6:
account_report()
elif choice == 7:
return
account_menu()
account_menu()
```
该程序中,定义了一个 `Account` 类,表示一个账户,包含了账户的姓名、余额和交易记录。同时,还定义了一些函数,用于实现账户的创建、存款、取款、余额查询、最近交易查询和账户报告查询等功能。通过调用这些函数,用户可以对账户进行操作。
在实际使用中,可以根据需求对代码进行适当的修改和扩展,以满足具体的业务需求。
阅读全文