简体   繁体   English

python中到期投资的增长收益率如何计算

[英]How to calculate growth yield of an investment on maturity in python

I am trying to calculate growth yield of an investment on maturity.我正在尝试计算到期投资的增长率。 My data is as follows:我的数据如下:

在此处输入图像描述

My code is as follows我的代码如下

a = input('principal amount\n')
principal=float(s)
a = input('prime rate\n')
prime=float(s)
a = input('number of years\n')
numberofyears=float(a)
if numberofyears <= 2:
  if principal <= 100000:
    growth = principal*prime
    print(growth)
  elif principal > 100000:
    growth = principal * (prime + (1.25 * prime))
    print(growth)
elif numberofyears <= 4:
  if principal <= 100000:
    growth = principal*(1.15*prime)
    print(growth)
  elif principal > 100000:
    growth = principal * ((1.15*prime) + (1.5 * prime))
    print(growth)
elif numberofyears > 4:
  if principal <= 100000:
    growth = principal*(1.25*prime)
    print(growth)
  elif principal > 100000:
    growth = principal * ((1.25*prime) + (2 * prime))
    print(growth)

What is wrong with my code?我的代码有什么问题? because when i put example data output is not as mentioned.因为当我把示例数据 output 和上面提到的不一样时。

For example:例如:

在此处输入图像描述

Output i am getting is 33125.0 Output 我得到的是 33125.0

There are 2 mistakes in your code.您的代码中有 2 个错误。 First your principal and your prime are assigned to the float of s which is not the the input.首先,您的委托人和素数被分配给不是输入的 s 的浮点数。 Then your equations don't apply the different rates for <=10e6 and >10e6.那么您的方程式不会对 <=10e6 和 >10e6 应用不同的比率。

Here's one way of doing it:这是一种方法:

principal=float(input('principal amount\n'))
prime=float(input('prime rate\n') )
numberofyears=float(input('number of years\n') )
if numberofyears <= 2:
 if principal <= 100000:
   growth = principal*prime
   print(growth)
 elif principal > 100000:
   growth = 1000000* (prime) + (principal-100000)*(1.25*prime)
   print(growth)
elif numberofyears <= 4:
 if principal <= 100000:
   growth = principal*(1.15*prime)
   print(growth)
 elif principal > 100000:
   growth = 1000000*(1.15*prime) + (principal-100000)*(1.5*prime)
   print(growth)
elif numberofyears > 4:
 if principal <= 100000:
   growth = principal*(1.25*prime)
   print(growth)
 elif principal > 100000:
   growth = 1000000*(1.25*prime) + (principal-100000)*(2*prime)
   print(growth)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM