# CPAN112 – Fundamentals of Numeric Computing – Assignment 04

## CPAN 112 | Assignment 4

### Compound Interest Program

Write a program to find the Compound Interest

• Use the python input() function that takes an input (principal amount, rate of interest,
time) from the user
• Time should be in years, months and days (You may reuse the time function created in
the simple interest lab)
• Remember, that user might not be mathematically familiar with the terms like compounding period, periodic rate. You might consider a statement that any person understands, like the one given below to make your program easy to use.
• “ Choose 1 for annual rate of interest, 2 for semi- annually, 4 for quarterly……..”
• Next, write a function to calculate the compound interest
• Print the compound interest. Print statement should have all the relevant information that user might be interested in.

NOTE-

• Run your program at least 3 times using different compounding periods. You should have 3 screenshots. Use Principal as \$10000, rate 10%, time as 1 year, 6 months and 143 days for all the 3 different cases. Only change the compounding period.

### Solution : Python Code

Note: Format it yourself.

 principle = float(input(“Enter Principle Amount: “)) ROI = float(input(“Enter Rate of Interest: “)) ROI = round(ROI/100, 4) # Calculating Time print(‘”Enter Appropiate Time below”‘) def get_time(): days = int(input(” Enter Days (0 for none): “)) months = int(input(” Enter months (0 for none): “)) year = int(input(” Enter year (0 for none): “)) totaltime = year + (months/12) + (days/365) return round(totaltime, 4) total_time = get_time() print() print(”’How your Interest is Calculated? Choose Number from below: “1” for annually “2” for semi-annually “4” for quarterly “12” for monthly”’) interest_frequency = int(input(“Interest Frequency: “)) # Formulas: # A = P * (1 + r/n)^(n*t) # CI = P * (1 + r/n)^(n*t) – P # Calculating Interest Compoundly def compount_interest(): return (principle * ((1 + ROI/interest_frequency)**(interest_frequency*total_time))) – principle Compound_Interest = compount_interest() # Printing OUTPUT print(“\n\nYour ALL INPUTS:\nPrinciple:”,principle,”\nRate of Interest:”,ROI*100,”\nTime (in years:”,total_time,”\nCompound Frequency:”,interest_frequency,”\n\n”) print(“Compount Interest is:”, round(Compound_Interest, 2)) print(“Total Amount is:”, round(Compound_Interest+principle, 2))