📅  最后修改于: 2023-12-03 15:07:35.056000             🧑  作者: Mango
有一家银行,要求开发一个程序,以帮助办公室管理员快速检查账户详情。管理员想要检查那些帐户余额低于 $ 1000 的账户。他们所想要的是一个 Python 程序,该程序的输出应列出这些账户的名称和余额。
管理员提供的账户相关数据存储在一个字典嵌套的列表中。列表中每个元素都是一个字典,代表一个账户。以下是一个示例列表:
account_details = [
{"account_number": 1001, "account_holder_name": "Alice", "account_balance": 1500},
{"account_number": 1002, "account_holder_name": "Bob", "account_balance": 800},
{"account_number": 1003, "account_holder_name": "Charlie", "account_balance": 3000},
{"account_number": 1004, "account_holder_name": "David", "account_balance": 590},
{"account_number": 1005, "account_holder_name": "Eric", "account_balance": 1800}
]
请写一个 Python 程序,该程序输出所有余额低于 $ 1000 的账户的名称和余额。
无需输入。
输出格式如下:
账户名称: <account_holder_name>, 余额: <account_balance>
账户名称: <account_holder_name>, 余额: <account_balance>
...
对于示例数据,输出应该如下所示:
账户名称: Bob, 余额: 800
账户名称: David, 余额: 590
以下是一个 Python3 程序,可以以 account_details
的形式输出余额低于 $ 1000 的账户的名称和余额:
account_details = [
{"account_number": 1001, "account_holder_name": "Alice", "account_balance": 1500},
{"account_number": 1002, "account_holder_name": "Bob", "account_balance": 800},
{"account_number": 1003, "account_holder_name": "Charlie", "account_balance": 3000},
{"account_number": 1004, "account_holder_name": "David", "account_balance": 590},
{"account_number": 1005, "account_holder_name": "Eric", "account_balance": 1800}
]
for account in account_details:
if account['account_balance'] < 1000:
print(f"账户名称: {account['account_holder_name']}, 余额: {account['account_balance']}")
代码片段已按markdown格式标明。