Python 程式用於計算單利


在本文中,我們將學習在 Python 3.x 或更早版本中計算單利。

單利是將日利率乘以本金,再乘以付款之間的天數來計算的。

在數學中,

Simple Interest = (P x T x R)/100
Where,
P is the principal amount
T is the time and
R is the rate

例如,

If P = 1000,R = 1,T = 2
Then SI=20.0
Now let’s see how we can implement a simple interest calculator in
Python.

示例

 現場演示

P = 1000
R = 1
T = 2
# simple interest
SI = (P * R * T) / 100
print("simple interest is", SI)

輸出

simple interest is 20.0

這裡的單利是透過三個算術乘積和一個算術除法獲得的。

現在讓我們看看宣告的變數的作用域。如下面的圖表所示,所有變數均宣告為 全域性作用域

結論

在本文中,我們學習了單利及其使用 Python 指令碼實現的內容。

更新於: 11-09-2019

1K+ 觀看

開啟您的 職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.