python将账户信息用户名和余额保存在一个字典的对象中分别定义3个函数实现用户查看余额存款取款的功能
时间: 2023-04-08 20:02:35 浏览: 118
这是一个技术问题,我可以回答。以下是三个函数的实现:
1. 查看余额:
```python
def check_balance(account_dict, username):
if username in account_dict:
return account_dict[username]
else:
return "该用户不存在"
```
2. 存款:
```python
def deposit(account_dict, username, amount):
if username in account_dict:
account_dict[username] += amount
return "存款成功,当前余额为:" + str(account_dict[username])
else:
return "该用户不存在"
```
3. 取款:
```python
def withdraw(account_dict, username, amount):
if username in account_dict:
if account_dict[username] >= amount:
account_dict[username] -= amount
return "取款成功,当前余额为:" + str(account_dict[username])
else:
return "余额不足"
else:
return "该用户不存在"
```
以上三个函数可以实现用户查看余额、存款和取款的功能。
阅读全文