首页 > 解决方案 > 我将如何舍入代码的输出?

问题描述

我是编程新手(昨天刚开始),我试图制作一个计算器,当给定变量输入时,它会得出数字。它工作得很好,但我想这样做,以便代码最后的输出被四舍五入。我将如何舍入代码的输出?

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()

标签: python

解决方案


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)

推荐阅读