Last active 10 months ago

這個 Python 函數計算投資報酬率 (ROI),衡量投資的盈利能力。ROI 公式為 (投資收益 - 投資成本) / 投資成本 * 100,用於評估投資回報的效率,適用於個人理財、企業投資和專案決策。

timmy revised this gist 10 months ago. Go to revision

1 file changed, 20 insertions

calculate_roi.py(file created)

@@ -0,0 +1,20 @@
1 + def calculate_roi(investment_cost, investment_gain):
2 + """
3 + 計算投資報酬率 (ROI) 的函數。
4 +
5 + :param investment_cost: 投資成本
6 + :param investment_gain: 投資收益
7 + :return: 投資報酬率 (ROI)
8 + """
9 + net_profit = investment_gain - investment_cost
10 + roi = (net_profit / investment_cost) * 100
11 + return roi
12 +
13 + # 使用函數計算 ROI
14 + investment_cost = 100 # 投資成本
15 + investment_gain = 150 # 投資收益
16 +
17 + # 輸出結果
18 + roi = calculate_roi(investment_cost, investment_gain)
19 + print(f"投資報酬率 (ROI): {roi}%")
20 +
Newer Older