我有以下内容应该返回一个感兴趣的值,它应该除以100.我该如何实现呢?
import math
p = int(raw_input("Please enter deposit amount: \n"))
r = float(raw_input("Please input interest rate: \n")) /100
t = int(raw_input("Please insert number of years of the investment: \n"))
interest = raw_input("Do you want a simple or compound interest ? \n")
A = p*(1+r*t)
B = p*(1+r)^t
if interest == "simple":
print (float(A))
else:
print(float(B))
答案 0 :(得分:1)
尝试这样的事情(提示您不需要import math
这样的事情):
from decimal import *
p = Decimal(raw_input("Please enter deposit amount:"))
r = Decimal(raw_input("Please input interest rate as a percentage:")) /100
t = int(raw_input("Please insert number of years of the investment:"))
n = 1 # You should really be asking how many times is the interest compounded per year? If the user chooses compound...
A = p*(1 + r)**t
B = p*(1 + r)**(n*t)
while(True):
interest = raw_input("Do you want simple or compound interest?")
if(interest.lower() == "simple"):
print(A)
break
elif(interest.lower() == "compound"):
print(B)
break
试试here!