python - 我将如何舍入代码的输出?
问题描述
我是编程新手(昨天刚开始),我试图制作一个计算器,当给定变量输入时,它会得出数字。它工作得很好,但我想这样做,以便代码最后的输出被四舍五入。我将如何舍入代码的输出?
print("What is the Initial Principal Value?")
P = int(input())
print("What is the interest rate?")
r = float(input())
print("What is the number of times interest is applied per time period")
n = int(input())
print("Finally, what is the number of time periods elapsed, this must be typed in terms of annual circumstances.")
t = int(input())
print(P*(1+(r/n))**(n/t))
round()
解决方案
Here it is:
print("What is the Initial Principal Value?")
P = int(input())
print("What is the interest rate?")
r = float(input())
print("What is the number of times interest is applied per time period")
n = int(input())
print("Finally, what is the number of time periods elapsed, this must be typed in terms of annual circumstances.")
t = int(input())
result = round(P * (1 + (r / n)) ** (n / t), 2)
print(result)
推荐阅读
- java - 单核细胞增多症
以被动的方式给用户 - python - 如何从 Flask 应用程序访问 type="file" 输入
- php - 如何在flutter中设置用户时间提示通知
- angular - Angular 9 - TestBed RouterTestingModule 中的 router.url 只读属性
- xcode - “swift package dump-package”命令在构建前操作和构建阶段不起作用
- excel - Excel,我如何计算具有相同名称的单元格旁边的值
- excel - excel错误测试单元格没有错误给出类型不匹配(CVErr(xlErrNA))
- go - 按列连接二维数组
- r - 将数据框转换为 R 中的二进制矩阵
- javascript - 使用像树这样的指针时打字稿记录错误