मराठी

Write a program that implements a user-defined function that accepts Principal Amount, Rate, Time, and Number of Times the interest is compounded to calculate and displays compound interest. - Computer Science (Python)

Advertisements
Advertisements

प्रश्न

Write a program that implements a user-defined function that accepts Principal Amount, Rate, Time, and Number of Times the interest is compounded to calculate and displays compound interest. (Hint: CI = P*(1 + r/n)nt)

थोडक्यात उत्तर
Advertisements

उत्तर

The hint given in the question has a mistake. The formula (P*(1+R/N)NT) will give us the amount, not the Compound Interest.

Program:
#Defining the function
def calculate(p,r,t,n=1):
    #calculating the amount
    amount = p * (1 + r/(n * 100))**(n * t)
    #calculating the compound interest and rounding it off to 2 decimal places
    ci = round(amount - p, 2)
    #displaying the value of the compound interest
    print("The compound interest will be ",ci)

#asking the principal, rate, and time
p = float(input("Enter the principal amount: "))
r = float(input("Enter the rate of interest: "))
t = float(input("Enter total time: "))
n = int(input("Number of times the interest is compounded in a year\n(e.g.Enter 1 for yearly, 2 for half-yearly): "))
if(n > 365):
    calculate(p,r,t,n)
else:
    print("Maximum number of times an interest is compounded can not be more than 365")

​OUTPUT:
Enter the principal amount: 10000
Enter the rate of interest: 8
Enter total time:  5
Number of times the interest is compounded in a year
(e.g. Enter 1 for yearly, 2 for half-yearly): 4
The compound interest will be  4859.47
shaalaa.com
  या प्रश्नात किंवा उत्तरात काही त्रुटी आहे का?
पाठ 7: Functions - Exercise [पृष्ठ १७२]

APPEARS IN

एनसीईआरटी Computer Science [English] Class 11
पाठ 7 Functions
Exercise | Q 5. | पृष्ठ १७२
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×