Untitled

 avatar
unknown
plain_text
3 years ago
1.6 kB
5
Indexable
import random
import math

Problem = input("What do you need in the equation f = a(1-r)^t? \n [f for final amount] \n [a for initial amount] \n [r for rate of increase/decrease] \n [t for time] \n Type: ")


if (Problem == "final"):
    a = float(input("Initial Amount (a): "))
    r = float(input("Rate (r): "))
    o = bool(input("Growth or Decay [answer with True or False]: "))
    t = float(input("Number of time (t): "))
    
    if(o):
        print("f = " + str(a * ((1+r)**t)))
    else:
        print("f = " + str(a * ((1-r)**t)))
        
elif (Problem == "a"):
    f = float(input("Final (f): "))
    r = float(input("Rate (r): "))
    o = bool(input("Growth or Decay [answer with True or False]: "))
    t = float(input("Number of time (t): "))
    
    if(o):
        print("a = " + str(f/((1+r)**t)))
    else:
        print("a = " + str(f/((1-r)**t)))
        
elif (Problem == "r"):
    f = float(input("Final (f): "))
    a = float(input("Initial Amount (a): "))
    o = bool(input("Growth or Decay [answer with True or False]: "))
    t = float(input("Number of time (t): "))
    
    if(o):
        print("r = " + str(((f/a)**(1/t))-1))
    else:
        print("r = " + str(-(((f/a)**(1/t))-1)))

elif (Problem == "t"):
    f = float(input("Final (f): "))
    a = float(input("Initial Amount (a): "))
    r = float(input("Rate (r): "))
    o = bool(input("Growth or Decay [answer with True or False]: "))
    
    if(o):
        print("t = " + str(math.log(f/a, 1+r)))
    else:
        print("t = " + str(math.log(f/a, 1-r)))
else:
    print("Invalid")
Editor is loading...