-1

I am trying to calculate growth yield of an investment on maturity. My data is as follows:

enter image description here

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.

For example:

enter image description here

Output i am getting is 33125.0

James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

1

There are 2 mistakes in your code. First your principal and your prime are assigned to the float of s which is not the the input. Then your equations don't apply the different rates for <=10e6 and >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)
kubatucka
  • 555
  • 5
  • 15