首页 > 编程知识 正文

Python 程序:计算简单利息

时间:2023-11-25 09:12:58 阅读:309112 作者:HNAO

在这个简单的 python 程序中,我们需要找到简单的兴趣。这是一个中级 python 程序。

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

  • Python 语法
  • Python 安装和设置
  • Python 运算符

什么是单纯的兴趣?

在这个求解好的 python 程序中,我们需要计算 Simple Interest,可以用公式 SI = pnr / 100 来计算。在哪里

  • p 为本金金额。
  • n 为年数。
  • r 为利率。

例如,假设我们以 10%的利率贷款 1000 英镑,期限为 1 年。然后通过公式 pnr/100 计算单利得出 1000 10 1 / 100 = 100。所以我们要给 100 卢比作为 1 年的利息。

python 中的单利是如何计算的?

现在在 python 编程语言中应用这个逻辑。我们使用 python 语言中的input函数接受本金、利率和时间的值。然后我们用公式 ( p n r ) / 100 计算利息。

算法

STEP 1: 使用 python 语言的输入函数接受本金金额、时间和利率的值。使用浮点和 int 数据类型将值转换为整数。

第二步:用公式 (pnr) / 100 计算单利。

STEP 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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。