用于计算单利的 Python 程序


2022年3月2日, Learn eTutorial
1507

在这个简单的 Python 程序中,我们需要计算单利。这是一个中级 Python 程序。

要理解这个例子,您应该了解以下 Python 编程主题

什么是单利?

在这个已解决的 Python 程序中,我们需要计算单利,可以使用公式 **SI = p*n*r / 100** 进行计算。其中:

  • **p** 是本金。
  • **n** 是年数。
  • **r** 是利率。

例如,假设我们借款 1000,利率为 10%,为期 1 年。那么通过公式 **pnr/100** 计算单利得到 **1000 * 10 * 1 / 100 = 100**。所以我们需要支付 100 卢比作为 1 年的利息。

Python 中如何计算单利?

现在将这个逻辑应用到 Python 编程语言中。我们使用 Python 语言中的 `input` 函数接收本金、利率和年限的值。然后我们使用公式 **(p * n * r) / 100** 计算利息。

算法

**步骤 1:** 使用 Python 语言中的 input 函数接收本金**金额**、**时间**和利率**利率**的值。使用 float 和 int 数据类型将值转换为整数。

**步骤 2:** 使用公式 **(p*n*r) / 100** 计算单利。

**步骤 3:** 在 Python 编程语言中使用 print 语句打印单利的值。

Python 源代码

                                          principle=float(input("Enter the amount :"))

time=int(input("Enter the years :"))

rate=float(input("Enter the rate :"))

si=(principle*time*rate)/100

print("The simple interest is:", si)
                                      

输出

Enter the amount : 1000

Enter the year : 1

Enter the rate : 10

The simple interest is : 100