python资产负债表
时间: 2023-11-08 11:00:27 浏览: 143
资产负债表
资产负债表是一份财务报表,用于显示企业在特定日期的资产、负债和所有者权益的情况。以下是一个简单的示例代码,用于计算并输出一个企业的资产负债表:
```python
# 资产负债表
class BalanceSheet:
def __init__(self):
self.assets = {}
self.liabilities = {}
self.owner_equity = {}
def add_asset(self, name, value):
self.assets[name] = value
def add_liability(self, name, value):
self.liabilities[name] = value
def add_owner_equity(self, name, value):
self.owner_equity[name] = value
def display(self):
print("资产:")
for asset, value in self.assets.items():
print(f"{asset}: {value}")
print("\n负债:")
for liability, value in self.liabilities.items():
print(f"{liability}: {value}")
print("\n所有者权益:")
for equity, value in self.owner_equity.items():
print(f"{equity}: {value}")
# 示例用法
bs = BalanceSheet()
bs.add_asset("现金", 10000)
bs.add_asset("应收账款", 5000)
bs.add_liability("应付账款", 2000)
bs.add_liability("长期负债", 8000)
bs.add_owner_equity("股东投资", 10000)
bs.display()
```
运行以上代码,将输出以下结果:
```
资产:
现金: 10000
应收账款: 5000
负债:
应付账款: 2000
长期负债: 8000
所有者权益:
股东投资: 10000
```
阅读全文