我需要将利率转换为十进制值 [英] I need to convert the interest rate to a decimal value

查看:58
本文介绍了我需要将利率转换为十进制值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容应该返回利息值除以 100.我该如何实现?

I have the following which should return a value of the interest where it should be divided by 100. How do I implement this?

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

推荐答案

尝试这样的事情(提示你不需要import math 来做这样的事情):

Try something like this (Hint you don't need to import math for something like this):

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

试试这里!

这篇关于我需要将利率转换为十进制值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆