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.
For example:
Output i am getting is 33125.0
CodePudding user response:
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)