# Arup Guha
# 10/20/20
# Example that calculates compounded interest
# Updated to use our own power function!

# Constant
MONTHS_PER_YEAR = 12

# Pre-conditions: base is a floating pt number, exp is an integer.
def mypow(base, exp):

    # If exp is negative, flip it and get the positive answer and then do 1/over.
    if exp < 0:
        return 1.0/mypow(base, -exp)

    # Exponent is positive.
    ans = 1
    for i in range(exp):
        ans = ans*base

    return ans

# Main Program
def main():

    # Get relevant values.
    principle = float(input("How much are you investing?\n"))
    rate = float(input("What is the yearly rate of return?\n"))
    time = int(input("How many years are you investing?\n"))

    # Compound annually.
    moneyAnnual = principle*mypow(1+rate, time)

    # Compound monthly.
    moneyComp = principle*mypow(1+rate/MONTHS_PER_YEAR, MONTHS_PER_YEAR*time)

    # Output result.
    print("Compounded annually, you will have $",moneyAnnual,".", sep="")
    print("Compounded monthly, you will have $",moneyComp,".", sep="")

# Run it!
main()
